Deb wrote: > > I've got a script which opens a filehandle to write print statments to a file. > But, I'm also running some system commands, and I would also like to send > stdout and stderr to that filehandle. I could just echo text to a file, or I > could use a filehandle. Which would be "better?" > > my $log = "/tmp/log.$$"; > > open(LOG, ">$log"); > print LOG "Commencing maintenance\n"; > > But, here's how I've handled stdout and stderr in a system statement: > > my $log = "/tmp/log.$$"; > > system("path-to-command >> $log 2>&1"); > > Is there a way to use a filehandle instead? Seems I'd have to take care of > block and non-blocking I/O. Methinks it may be simpler just to stick with > printing directly to $log and not the FH, LOG.
You could do something like this: use IPC::Open3; my $log = "/tmp/log.$$"; open LOG, '>', $log or die "Cannot open $log: $!"; print LOG "Commencing maintenance\n"; my $pid = open3( 0, '>&LOG', 0, 'path-to-command' ); John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]