Webベースのアプリケーションを開発していますが、Matlabスクリプトを実行していくつかの情報を処理する必要があります。
問題は、同時に実行するMatlabプロセスの最大数に制限があることです。このため、プロセスのいずれかがクラッシュしたかどうか、およびどのプロセスがクラッシュしたかを知るために、各プロセスのPIDを取得する必要があります。
PIDを取得するためにいくつかのメソッドを使用しましたが、何らかの理由で「notepad.exe」のような単純なコマンドを実行すると正常に機能し、正しいPIDを取得しますが、スクリプトを実行すると間違ったPIDを取得します。
私が試した方法の1つはこれです:
$process = "matlab";
$command = "-sd ".$softExecPath." -r \"analyse('".$videoDataPath."', '".$id_video_data."') \" ";
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->exec($process." ".$command);
$pid = intval($oExec->ProcessID);
そしてもう1つは:
$process = "matlab";
$command = "-sd ".$softExecPath." -r \"analyse('".$videoDataPath."', '".$id_video_data."') \" ";
$command = $process." ".$command;
// use psexec to start in background, pipe stderr to stdout to capture pid
exec("C:/AppServ/www/PsTools/psexec.exe -d -accepteula $command 2>&1", $output);
// capture pid on the 6th line
preg_match('/ID (\d+)/', $output[5], $matches);
$pid = $matches[1];
どちらもPIDを取得しますが、実際のPIDはありません。