PaulM
PaulM

Reputation: 375

I have a system call that somehow is causing malformed header from script Bad header

I have a Perl CGI program. myperlcgi.pl

Within this program I have the following:

my $retval = system('extprogram')

extprogram has a print statement within.

The output from extprogram is being included within myperlcgi.pl

I tried adding

> output.txt 2>&1 

to system call but did not change anything.

How do I prevent output form extprogram being used in myperlcgi.pl.

Surprised that stdout from system call is being used in myperlcgi.pl

Upvotes: 0

Views: 121

Answers (1)

Ed Sabol
Ed Sabol

Reputation: 452

The system command just doesn’t give you complete control over capturing STDOUT and STDERR of the executed command.

Use backticks or open to execute the command instead. That will capture the STDOUT of the command’s execution. If the command also outputs to STDERR, then you can append 2>&1 to redirect STDERR to STDOUT for capture in backticks, like so:

my $output = `$command 2>&1`;

If you really need the native return status of the executed command, you can get that information using $? or ${^CHILD_ERROR_NATIVE}. See perldoc perlvar for details.

Another option is to use the IPC::Open3 Perl library, but I find that method to be overkill for most situations.

Upvotes: 4

Related Questions