On Mar 2, 2:49 pm, teva...@gmail.com (Thomas Evangelidis) wrote: > Hi again, > > I'm digging out this thread cause it seems that my problem has been only > partially solved. Indeed "my @myout = `program file`;" can save the output > of my program to an array for parsing but this doesn't happen when I use > programs with output that cannot be redirected to a file (i.e. error > messages). In my first message I describe how I can achieve that in bash > using the >$ operator : > > apbs input.in >$ output.txt # '>' doesn't work here > > How can I block the output of that program when invoked from a perl script? > The case here is that this script is run by a java program multiple times > concurrently, and the java program also reads it output using buffered > readers which overflow with useless data printed by apbs program as shown > above, which results to a crash. > > thanks in advance, > Tom > > 2009/2/19 Wagner, David --- Senior Programmer Analyst --- CFS < > david.wag...@fedex.com> > > > > > You can do undef @myout; > > but it really depends upon what system you are running under and how > > they handle the release of memory. This should cutdown, but you could > > also use brackets like: > > > { > > my @myout = `program file`; > > # now process what is in @myout and either save to > > another arry which you want to write eventually or > > # write to a file with the necessary data that meets > > your criteria > > > } > > after the }, the my @myout would be released
I am not sure if I understood your problem completely. I ran into an issue where I had to run another script from perl and redirect the STDOUT and STDERR to a file something like apbs.pl input.in >$ output.txt I used perl IPC open3 library. # construct command my $command = "$script $param 2>&1" # 2>&1 will redirect STDERR to STDOUT # to set buffering of STDXXX off to get the output in correct order $| = 1; select((select(STDERR), $| = 1)[0]); # Execute command eval{ $pid = open3($infh, $outfh, $errfh, $command); }; die "open3: $...@\n" if $@; # $clog is the handle for the file we wanna redirect the output print $clog "\n___________________________________________________________________ \n"; while(my $line =<$outfh> ){ print $clog $line;} print $clog "\n___________________________________________________________________ \n"; eval {setpriority 0,0, (getpriority 0,0)+4; }; #lower the priority of the parent process waitpid($pid,0); Hope this helps!!! Rajesh Gupta -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/