Marty Meyers wrote:
I have the following line in a php file:
$msg= exec("perl $scriptPath/insert.pl $d $u $t 2>&1", $returnVal);
Can someone explain the "2>&1" argument?
Error redirection.
&1 is stdout (standard output stream)
&2 is stderr (standard error stream)
if you do
command | more
and you get valid output, with lines of errors in between the output,
the errors are not piped to more and will mess up the display
unless you do:
command 2>&1 | more
which will work fine.
Or if you do
command > output.txt
output.txt does not contain any errors created(output) by command,
only the normal output of the command.
and
command 2> errors.txt
will contain only errors, none of the normal output.
You can do
command > output.txt 2> errors.txt
to get seperate output for normal and error reports
in two different files
command 2>&1 > output_and_errors.txt
to get all output into one report.
(Which places the errors in the same stream as the normal output,
and then redirects the normal output to output_and_errors.txt)
The reason your exec has 2>&1 is so
that the return value will contain any
possible errors and/or normal output.
If this was not added and if the
perl command should fail, you would
not even have that information in
returnVal.
Second problem, this same line of code when run from the unix command line
returns the following error:
sh: /perl: No such file or directory
Just checking, are you saying that the
command works fine with:
$> perl insert.pl
but that it does not work from neither
php php_file_containg_exec.php
nor
$> perl $scriptPath/insert.pl $d $u $t 2>&1
Did you substitute $scriptPath; $d and $u with
the relevant values before trying this, or
exactly what did you do ?
--
Etienne Marais
Cosmic Link
South Africa