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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.