Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Problem invoking Matlab from Perl: works on Linux, fails on Windows

by arcnon (Monk)
on Oct 03, 2007 at 16:52 UTC ( [id://642450]=note: print w/replies, xml ) Need Help??


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

I read you question but I think this is what you are looking for:
my $matlab_cmd_str = system("$path_to_matlab -nodesktop -r my_script +"); my $file = "matt_log.txt"; open(F, ">$file") or die "can't open file"; print F $matlab_cmd_str; close(F) or die ""can't close;
  • Comment on Re: Problem invoking Matlab from Perl: works on Linux, fails on Windows
  • Download Code

Replies are listed 'Best First'.
Re^2: Problem invoking Matlab from Perl: works on Linux, fails on Windows
by jim99 (Initiate) on Oct 10, 2007 at 18:10 UTC
    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://642450]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-04-25 17:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found