in reply to Re: Problem invoking Matlab from Perl: works on Linux, fails on Windows
in thread Problem invoking Matlab from Perl: works on Linux, fails on Windows

This turned out not to be a Perl issue at all: matlab, when invoked from a Windows command line, returns immediately after launching a separate Matlab process/Windows. When launched from a command line in Unix, Matlab opens in a separate process/window, but the command line process does not exit until a File/Exit in the Matlab window. The Mathworks, makers of matlab, came through with a solution: use an undocumented command line argument in Windows: "-wait". With this arg, the matlab command line process does not exit until Matlab exits. Before this solution appeared, I had come up with another, which seems to work but is far from bulletproof:
my @matlab_pids_before = find_win32_pids("matlab"); system($matlab_cmd_str) == 0 or die("Unable to invoke $matlab_cmd_str\ +n"); my @matlab_pids_after = find_win32_pids("matlab"); my @pid = find_new_pid(\@matlab_pids_before, \@matlab_pids_after); if ($#pid != 0) { die(sprintf("Expecting one new matlab PID, found %d new matlab pids" +,1+$#pid)); } waitpid($pid[0], 0); # Wait here until Matlab completes.
This method is not atomic, but will probably be ok in the environment the code will run in. find_win32_pids() uses pslist, a free Microsoft download, that's a ps lookalike. I was unable to get WMIC to work from Perl, although it worked ok from the command line. Thanks to everyone for their help.
  • Comment on Re^2: Problem invoking Matlab from Perl: works on Linux, fails on Windows
  • Download Code