[PLUG] perl Open3 : does not write errors in the file provided.

Gaurav Mishra gauravtechie at gmail.com
Thu Oct 4 22:44:57 IST 2007


On 10/4/07, भरत लोिहया <bharatlohiya at gmail.com> wrote:
> Hello all,
>
> I have a problem while writing a program in perl.
> I am creating a process using Open3. Here goes the code.
> ********
> use Symbol qw(gensym);
>
> my $RD=gensym();
> my $WR=gensym();
> my $ER=gensym();
> my $ERR_LOGS='Error_GDB_'.time();
> print STDOUT "$ERR_LOGS\n";
> open( $ER,">>$ERR_LOGS") || die "Unable to open error file $ERR_LOGS $!\n";
>
> my $pid=open3($WR,$RD,$ER,$process) || die "$!\n";  <==== problem
> ........(firing commands by writing on $WR and reading output from $RD, but
> it should write the errors on $ERR_LOGS, as $ER is associated with it)
> **********
> This is a small part of code I have written, the problem I am facing here is
> that the function open3 is not writing the errors on the $ERR_LOGS file. But
> while execution I can see " /proc/<pid>/fd/4", has the errors of the
> process.
> With this code, it gets stuck somewhere in the program execution, because of
> not getting fd/4 flushed(in my opinion). To overcome that I tried replacing
> $ER in Open3 statement with "STDERR" which subsequently flushes all errors
> (and does not get stuck anywhere and run the whole process till the end
> successfully, but no logging of errors), and hence I can not see any error
> file descriptor associated with the process in /proc.
> Since I want to capture the errors according to the requirement of the
> project, I tried various other methods but nothing is running the full
> program and capturing the process errors.
> The other methods I tried are.
> 1. open the ERR_LOGS file with another $PROC_ERR and passed this with open3
> instead of $ER. => got stuck and did not log the error in file.
> 2. open the error file with $PROC_ERR and passed $ER with open3, and reading
> from $ER as I read $RD with the help of "sysread function". But it get stuck
> when it first encounters reading $ER.
> etc.
>

Try capturing the STDERR into the temp file and calling them , kinda of
use IO::File;
local *CATCHERR = IO::File->new_tmpfile;
my $pid=open3($WR,$RD, ">&CATCHERR" , $process) || die "$!\n";

Well IMHO capturing the STDERR directly should work

Thanks and Regards
Gaurav Mishra
-- 
Linux User #348873
ILUGD General Secretary, GZLUG  Moderator
RKGIT Alumni(Guiding Light)
Software Engineer , UnitedVillages
http://gauravmishra.info/blog
"When i can run , i will run , When i can walk , i will walk, When i can
crawl , i will crawl. But i will not stop moving forward"


More information about the Plug-mail mailing list