关于exec()函数和时间

发布于 2024-09-14 06:16:20 字数 483 浏览 1 评论 0原文

我将首先显示一些代码:

echo exec("compile\\save.exe Untitled.c tmpUntitled.c");

我有一个程序,名为 save.exe 我想知道它是否已经停止?
如果停止了,好的...做点什么...

如果没有,可能是一个错误,或者一个循环...
现在:我想构建相同的方法来控制程序使用的时间,并设置一个限制(超出时间限制,类似这样......)

有人有建议吗?




编辑[1]:save.exe是一个用C语言编写的程序,使用两个参数:source和destiny。
popen 只是不执行 save.exe,我这样说是因为它不再生成命运(使用 exec 它会发生);

I'll show some code, first:

echo exec("compile\\save.exe Untitled.c tmpUntitled.c");

I have a program, named save.exe and i want to know if it already stopped?
If stopped, ok... Do something...

If not, may be an error, or a loop...
Now: I want to build same way to control the time that program use, and put a limit (time limit exceed, something like this...)

Any one has a sugestion ?




Edit[1]:save.exe is a program wrote on C language, and use two parameters: source and destiny.
popen just don't execute save.exe, i say this because it don't gerenate anymore the destiny (with execit happens);

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

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

发布评论

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

评论(1

深爱成瘾 2024-09-21 06:16:20

exec() 将在 exec 程序运行时挂起您的脚本。仅当外部程序终止时才会返回控制权。如果您想查看程序是否挂起或正在等待输入等,您可以使用 popen(),它返回一个文件句柄,您可以从中读取程序的输出。此时,您可以执行轮询循环来查看是否有任何输出:

$app = popen("your shell command here");

while($output = fgets($app)) {
   // handle output
   sleep(5); // sleep 5 seconds
}       

如果您想将某些内容作为输入发送到应用程序,那么您必须使用 proc_open(),它允许脚本和外部程序之间的双向通信。

exec() will suspend your script while the exec'd program is running. Control will be returned only when the external program terminates. If you want to see if the program's hung up or waiting for input or somesuch, you use popen(), which returns a filehandle from which you can read the program's output. At that point you can do a polling loop to see if there's been any output:

$app = popen("your shell command here");

while($output = fgets($app)) {
   // handle output
   sleep(5); // sleep 5 seconds
}       

If you want to send something to the app as input, then you have to use proc_open(), which allows bi-directional communication between your script and the external program.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文