Windows 和 Linux 上的 exec() 参数 /dev/null 和 & 符号?

发布于 2025-01-05 01:25:59 字数 604 浏览 3 评论 0原文

来自 exec() 手册页:

如果一个程序用这个函数启动,为了让它 继续在后台运行,程序的输出必须是 重定向到文件或另一个输出流。如果不这样做将会 导致 PHP 挂起,直到程序执行结束。

所以,看来我应该重定向输出到某个东西,并在Linux下添加与号,以使我的脚本真正在后台运行

我应该如何“翻译” Windows 的 /dev/null& ?任何机会使用 php:// 来制作操作系统安全吗?

exec('php ' . __DIR__ . '/script.php > /dev/null &');

From exec() manual page:

If a program is started with this function, in order for it to
continue running in the background, the output of the program must be
redirected to a file or another output stream. Failing to do so will
cause PHP to hang until the execution of the program ends.

So, it seems i should redirect output to something and add ampersand under Linux, to make my script truly running in background.

How i'm supposed to "translate" /dev/null and & for Windows? Any chance to use php:// to make it OS safe?

exec('php ' . __DIR__ . '/script.php > /dev/null &');

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烂人 2025-01-12 01:25:59
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run("cmd /C dir /S %windir%", 0, false);
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run("cmd /C dir /S %windir%", 0, false);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文