You are here: Re: 2>&1 arg in exec(perl.... + "sh: /perl not found error" TIA for help « PHP Programming Language « IT news, forums, messages
Re: 2>&1 arg in exec(perl.... + "sh: /perl not found error" TIA for help

Posted by Etienne Marais on 12/07/05 03:51

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация