I am working on a Perl script which uses the system to run a pipe of external commands like this: / P>
system ("command1 | command2 | command3" gt; outfile);); Now I want to capture STDERR in one file with all these commands. It works in OS X:
system ("command1 2> error.log | command2 2> error.log | command3 2> error.log> outfile"); but not in Windows, where I get an error:
"The process can not access the file because it is being used by another process "
Is there any workaround? I need to be portable, so I would like to avoid the module if possible. Thanks in advance.
This is because '& gt;' Do not like sharing files, give your error log to each step of the pipeline, and then execute something like this after the pipeline ends:
system ("cat error1.log Erorr2.log error3.log> error.log "); There is a platform independent way to collect logs:
my @error_logs = qw (error1.log error2.log error3.log) ; Open my $ errlog, "> gt; & gt;", "error.log" || Die "Problem opening check error: $!"; Open my $ sublog (@error_logs) first (open my $ FH, "& lt;", $ sublog || die "oh boy: $ sublog: $!"; Print "$ sublog:" INR log $ $ Fh; about $ fH;} $ $ errlog; But there also exists and if you decide to redo this way.
1) The name of selfish mani has been corrected which will not share the file. / P>
2) Added log file archive
No comments:
Post a Comment