开发者

Error handling for popen

I am using popen in PHP to execute a TCL file .

     $cmd='C:/wamp/www/Tcl/bin/tclsh84.exe';  //windows
             $开发者_开发问答ph = popen($cmd,'w')

But if someone restarts the machine or the tclsh84.exe process is killed . How do I know this error condition has occured ? $ph is not returning 0 in these conditions.

Regards, Mithun


you see the documentation of the tasklist utility from there. This utility is a kind of task manager in command line (a bit less feature since you can only list process and not affect them). Having that utility accessible on your server, you can use exec function to get list of process and work with that.

a probable code would be something like that:

 function isTCLRunning(){
   $running = false;
   exec('tasklist.exe /fo CSV /fi tclsh84.exe', $output);

   return count($output) == 1
  }

note: this is completly untested you might want to play a bit with tasklist and make sure it is returning expected output before starting to code your PHP function.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜