473,379 Members | 1,260 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

2>&1 arg in exec(perl.... + "sh: /perl not found error" TIA for help

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?
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

I've verified that perl is located in /usr/bin/
/usr/bin is in the environment variable "PATH"
all the directories from php program to the root and back down to usr/bin
have 755 permissions.
if I run the program (insert.pl) from the command line it works
I've tried putting the following in both the php and perl programs:
#!/usr/bin/perl
#!/usr/bin

Any suggestions would be appreciated.

Thanks
Marty
Dec 7 '05 #1
2 10322
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

Dec 7 '05 #2

Hi Etienne,
Thanks for the detailed explanation of "2>&1". I should have recognized
that from the windows cmd processor which is about the same.
$msg= exec("perl $scriptPath/insert.pl $d $u $t 2>&1", $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

Marty ans: Yes, it works-with args, ie perl insert.pl 28 2
/var/www/....../vehicles.txt
but that it does not work from neither
php php_file_containg_exec.php Marty ans: correct, it fails BTW-the php file is ftpupload.php
nor

$> perl $scriptPath/insert.pl $d $u $t 2>&1 Marty ans: Very interesting, using the $scriptPath in the command line
fails. It starts the script(I have a print statement in it) but it does not
run the entire program.
Did you substitute $scriptPath; $d and $u with
the relevant values before trying this, or
exactly what did you do ? Marty ans: ran it two ways (both from command line, ie php ftpupload.php):
I used variables-failed
I used the real values for all variables and changed the double quotes
to single quotes in the ftpupload.php file-Still failed

Marty ans: Thanks
--
Etienne Marais
Cosmic Link
South Africa


Dec 7 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bob | last post by:
I use saxon transformer as XSLT engine, but I have a problem: --- Error reported by XML parser: reference to entity "&{0};" not defined. ---- In the source document there are many entites...
2
by: Eric Osman | last post by:
Hi, I'm looking for a javascript function that will convert input such as this: <CLUB Code=" into this: &lt;CLUB Code=&quot;
4
by: barney | last post by:
Hello, I' m using .NET System.Xml.XmlDOcument. When I do the following: XmlDocument xml = new XmlDocument(); xml.Load("blah"); .... xml.Save("blub"); I've got the problem that the following...
5
by: martin | last post by:
Hi, I would be extremly grateful for some help on producing an xml fragemt. The fragment that I wish to produce should look like this <Addresses> <Address>&qout;Somebody's Name&quot;...
2
by: andrew007 | last post by:
I do xml / xslt transformation using asp.net but I found any value (w/xml format) in xml node html-encoded to &lt and &gt format if it's > or < tag. Since I have sub xml data in a parent xml node...
3
by: divya | last post by:
Hi, I have a table tblbwday with 2 fields Name and Birthday.I have written this script for displaying evryday names of the people on that day. <% set objConn...
5
by: John Nagle | last post by:
This, which is from a real web site, went into BeautifulSoup: <param name="movie" value="/images/offersBanners/sw04.swf?binfot=We offer fantastic rates for selected weeks or days!!&blinkt=Click...
3
by: Pappy | last post by:
SHORT VERSION: Python File B changes sys.stdout to a file so all 'prints' are written to the file. Python file A launches python file B with os.popen("./B 2>&^1 >dev/null &"). Python B's output...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.