apache includes the STDOUT of the programs called by my perl scripts!
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
apache includes the STDOUT of the programs called by my perl scripts!
Hi!
I just moved to a new server.
http 2.2.2
perl 5.16.0
When I call a binary from a perl cgi using system(), apache receives its STDOUT output!
So obviously it complains about "malformed header" and returns 500
It never happened before, I don't understand.
I checked the commands with "command > file" and there is nothing as STDERR, everything goes into "file", it is pure STDOUT.
Don't worry, it is perfectly okay; this is how CGI works: the standard output of the CGI program is sent to the client.
When you use system, you can redirect stdout with >file and/or stderr with 2>file.
Don't worry, it is perfectly okay; this is how CGI works: the standard output of the CGI program is sent to the client.
When you use system, you can redirect stdout with >file and/or stderr with 2>file.
All right, but I didn't change my programs and the previous server didn't have that problem :-/
It happens only now that I installed a new httpd and new perl on a new server.
Do I really have to search in all my programs to add >/dev/null 2>&1 ????
This is happening because the shell invoked by the call to system() is inheriting its parent's (i.e. the httpd's) STDOUT, and (as NevemTeve said) CGI scripts invoked by httpd use STDOUT as the file descriptor used for their output. You have a couple of options:
Redirect the STDOUT of subshells created by system() somewhere else (e.g. /dev/null - take care, because this isn't portable):
Code:
system("command > /dev/null");
Use the command operator to capture the subshell's STDOUT (and assign its return value to a scalar if you want to inspect it):
Use a module for handling external processes, like Proc::Reliable
My preferred approach would be #2 - #3 is fine, but it introduces a new non-standard dependency when Perl's built-in behaviour is good enough for most purposes (and it's probably slower). Also make sure that what you're trying to do by executing the external command hasn't already been done by someone else more thoroughly on CPAN. Don't make life harder than it needs to be.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.