Perl stderr&stdout redirect question
Hi,
I am trying to do the following in a perl script, my $disk="hdc"; system("dd if=/dev/sdb of=/dev/${disk} &> /tmp/${disk}.txt &"); Basically I want to start a dd, output stdout and stderr to a file and fork it. I have another bash script which does a "kill -USR1 `pidof dd`" in the background which runs once a second. Sending USR1 as you might know causes dd to send the current status out to stderr. It all works apart from that the file /tmp/hdc.txt becomes blank if I run it form within perl. If I just type "dd if=/dev/sdb of=/dev/hdc &> /tmp/hdc.txt &" in a bash prompt then it does work exactly as I want it to. Why is this? What am I doing wrong? I can only assume that it is perl who steals all the stdout and wont let me redirect it to a file? Thanks! |
/bin/sh redirection of both stdout and stderr is:
Code:
program 1>screen.log 2>&1 |
Quote:
|
Quote:
I am trying to run the script on a lighttpd server which is running as root (I know, bad but it is a internal network server which is just going to be used to mirror hard drives). I can see dd in the process list so it does appear to start and the hard disk activity light is flashing so it appears to be copying fine as well. It is just that I cant seem to grab the stderr. What could be causing this? |
Quote:
Code:
my $disk="hdc"; This webpage has some interesting information on the importance of the order of redirection. Anyway, it worked here for this example: Code:
#!/usr/bin/perl -w |
Quote:
This seems to be the case as I can see a lot of stderr output in it. However not the one I am trying to redirect. I have read a bit about people suggesting to use Tie::STDERR or CGI::Carp but I am unsure how to do this. |
All times are GMT -5. The time now is 12:12 AM. |