When the system call was made in the program it would launch the program in this case xv. The execution of our program would stop until after we had closed our xv program. After we close xv however our Perl script would continue to run the code after the system statement.system "xv $imagename";
Another way is to use open with a pipe. Basically this works the same as working with a filehandle that you're reading from. All you do is something like:$output=`more datafile`;
This open call returns the process id of the process it spawns. Then you just read from the handle with the <> operator and close it when you're finished. If you think about how you write to files you can probably guess how you write to processes.$pid=open READER, "programname arguments|" or die "Can't run the progr +am: $!\n"; while(<READER>){ $output.=$_; } close READER;
All you have to do is open the process with the pipe on the left side, and then handle it like you would handle printing to a file.$pid=open WRITETOME, "|programname arguments" or die "Couldn't fork pr +ocess"; print WRITETOME "write this\n"; close WRITETOME;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Working with other processes and programs
by Linuxboy (Novice) on Sep 18, 2002 at 18:25 UTC | |
by DeadPoet (Scribe) on Jan 09, 2011 at 15:49 UTC |