Php shell_exec在不需要输出时不工作

Php shell_exec在不需要输出时不工作,php,shell-exec,Php,Shell Exec,我正在尝试使用shell_exec运行一个php脚本,但似乎无法正常工作 我有3个文件:index.php、write.php和file.php 在write.php中,我有以下内容: $file = 'file.txt'; $contents = 'it works'; sleep(5); file_put_contents($file, $contents); shell_exec('path_to_file\php.exe write.php &'); 这将向file.php写

我正在尝试使用shell_exec运行一个php脚本,但似乎无法正常工作

我有3个文件:index.php、write.php和file.php

在write.php中,我有以下内容:

$file = 'file.txt';
$contents = 'it works';
sleep(5);
file_put_contents($file, $contents);
shell_exec('path_to_file\php.exe write.php &');
这将向file.php写入一些内容

在index.php中,我有以下内容:

$file = 'file.txt';
$contents = 'it works';
sleep(5);
file_put_contents($file, $contents);
shell_exec('path_to_file\php.exe write.php &');
这是可行的,但需要等待脚本完成。现在,我尝试在不需要等待脚本完成的情况下完成这项工作,但没有结果。我所拥有的是:

shell_exec("path_to_file\php.exe write.php > /dev/null 2>/dev/null &");
这是行不通的;没有数据写入文件.php

有人能帮忙吗?
提前感谢。

如果您想等待它完成,为什么要将其作为后台作业运行(使用
&
)?@Phylogenesis,我不知道。这是为了在后台运行而不必等待脚本完成。我突然想到您正在使用Windows。这些重定向和
&
符号是Unix ISM,在Windows中无法正常工作。要在Windows的后台运行命令,请在命令前面加上单词
start
。例如:
start path\u to\u file\php.exe write.php
。如需更多帮助,请参阅您的回答。我正在windows上运行wamp服务器。我照你说的做了,但是结果是一样的。它等待脚本完成,这不是我想要的。问题是,当我添加
/dev/null
时,什么都不会发生。
/dev/null
在Windows中是没有意义的。等价物是
>NUL