开发者

About exec() function and time

I'll show s开发者_运维技巧ome 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);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜