关于exec()函数和时间
我将首先显示一些代码:
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 exec
it happens);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
exec()
将在 exec 程序运行时挂起您的脚本。仅当外部程序终止时才会返回控制权。如果您想查看程序是否挂起或正在等待输入等,您可以使用popen()
,它返回一个文件句柄,您可以从中读取程序的输出。此时,您可以执行轮询循环来查看是否有任何输出:如果您想将某些内容作为输入发送到应用程序,那么您必须使用
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 usepopen()
, 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: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.