Maybe this is a FAQ, but I can't find it in perlfaq8, or here on perlmonks.
On Linux, I call a matlab script from Perl:
1. $matlab_cmd_str = "$path_to_matlab -nodesktop -r my_script";
2. open(RUN_MATLAB, "$matlab_cmd_str |")
or die("Can't run $matlab_cmd_str: $!\n");
3. while(<RUN_MATLAB>) {
4. print FH "$_";
5. }
6. my $return_status = close(RUN_MATLAB);
7. unless($return_status) { print STDERR "There was a problem: $?\n"
+}
Output sent to the matlab command window is captured to a file. Execution does not get to line 7 until the exit at the end of the matlab script is reached.
However, when I run this on WinXP, the code immediately executes to line 7, instead of waiting until the matlab script completes execution.
I get similar behavior when I replace the piped open with a
$sts = system($matlab_cmd_str);
or with a
my $stdout = qx/$matlab_cmd_str/;
Is there a way of getting the Linux-like behavior on WinXP,
so execution of the Perl script pauses until the matlab script completes?
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.