ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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?
Thank you, I tried this but still the same problem. It did however work in the shell, but not in Perl.
Okay ignore everything in this thread. The reason doesnt seem to be due to Perl. I should have mentioned that this script is a CGI script. If I run the script in a shell it does actually work as well.
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?
my $disk="hdc";
system("dd if=/dev/sdb of=/dev/${disk} > /tmp/${disk}.txt 2>&1 &");
The first ">" tells the shell to redirect stdout to the file. The final "2>&1" tells the shell to redirect stderr to stdout. That has to be last. I forget why.
my $disk="hdc";
system("dd if=/dev/sdb of=/dev/${disk} > /tmp/${disk}.txt 2>&1 &");
The first ">" tells the shell to redirect stdout to the file. The final "2>&1" tells the shell to redirect stderr to stdout. That has to be last. I forget why.
Sorry, that didnt work either. But I dont think the redirect is the problem anymore. After some googling I have found out that most webservers wont allow stderr to be redirected. It seems that they will take any stderr output and put it to their error.log file.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.