Re: Run sequential processes (Matlab, SAS, etc.) from Perl
by Corion (Patriarch) on Nov 26, 2010 at 19:56 UTC
|
| [reply] |
Re: Run sequential processes (Matlab, SAS, etc.) from Perl
by chrestomanci (Priest) on Nov 26, 2010 at 22:48 UTC
|
#!/bin/bash
matlab myscript.m mylogfile.txt
sas mysascode.sas
# ... etc.
Or if you are truly impatient, you can put the whole thing on one command line. Just separate the commands with semi colons (;), double check it is correct, and hit enter. | [reply] [d/l] |
Re: Run sequential processes (Matlab, SAS, etc.) from Perl
by chrestomanci (Priest) on Nov 27, 2010 at 14:12 UTC
|
If you must edit your original question, then please don't change the meaning. If someone comes to this thread in a years time they won't know what you originally asked.
In answer to your second question, pipe symbols (|) should be OK in your crontab, but personally, if I am doing anything remotely complex in a cronjob, I always write a script, and then call it from cron.
The reason is that any job called directly from cron gets a very simple shell with hardly any features, and not much environment set-up, so stuff that works from your normal command line sometimes does not from cron. If you call a script you can put a hash-bang line in to bash, and then set-up your PATH and the rest of your environment explicitly, so everything works.
| [reply] [d/l] |
|
|
Thanks for the response. I meant to reply to my post, but accidentally deleted it instead. I've tried to recreate it.
| [reply] |
Re: Run sequential processes (Matlab, SAS, etc.) from Perl
by 7stud (Deacon) on Nov 26, 2010 at 23:39 UTC
|
Maybe you can do this directly in Unix
In unix, it's as simple as:
$ prog1 | prog2 | prog3 | prog4
| [reply] [d/l] |
|
|
Okay, I tried this at the command line, but it immediately started processing BOTH before the first had finished:
matlab mycode.m log.txt | perl myperlscript.pl
the matlab code spits out a csv file that is needed in the perl script.
The matlab code is run in the background. Maybe that's affecting this.
By the way, I also tried using semicolons as suggested, but the result was the same. I need to wait until the first process has completed before starting the second.
| [reply] |
|
|
The pipe idea (prog1 | prog2 | prog3) works best when these prog's are designed to read STDIN and output to STDOUT (not directly to files). I don't think that is what you want.
If I understand correctly, when you type in the command "matlab...", that program starts a process in the background and returns immediately to the command line while this background process is still running. If you type in a command that uses the output file that matlab creates, it doesn't work because matlab is still working on that output file. So, make a simple script file with the commands as described by others. Right after the matlab command, put in the "fg" command. That moves the most recently started background process into the foreground. Now the next command won't get executed until this now foreground process finishes.
An alternative is to use the "wait" command. wait command. Just put "wait" after the matlab command. See the example in the link.
| [reply] |
|
|