shell_exec returns empty string

前端 未结 4 1943
隐瞒了意图╮
隐瞒了意图╮ 2021-01-21 03:06

When I execute my command in PHP with shell_exec it always returns an empty string. I tried shell_exec(\'ls -l\'); and it works. I put the command as

4条回答
  •  温柔的废话
    2021-01-21 03:51

    You may want to try " > file.txt 2>&1" at the end of your command. It will redirect the outputs to a separate file.

    $command = "cmd command > outputs.txt 2>&1";
    shell_execute($command);
    

    You'll end up with a file that looks something like this:

    b'cmd command output contents\r\n'
    

提交回复
热议问题