473,574 Members | 2,494 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 10337
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_erro rs.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_erro rs.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_contai ng_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_contai ng_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
1648
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 (like Ö) that the parser doesn't recognize. Why? The document is malformed? Can I configure the parser to ignore unknown
2
20499
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
14774
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 expression: .... snip ...
5
3425
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; &lt;me@mydomain.com&gt;</Address> </Addresses>
2
6834
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 as a value. Check out the following problem. I want to convert the value in <WpDatesXml> node to have a valid "<" and ">" instead of &lt or &gt...
3
3080
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 =server.createobject("ADODB.connection") objConn.open "DSN=Photo" Dim sqlSELsite,ObjRSSel sqlSELsite = "SELECT Name FROM tblbwday WHERE B'day ="& date() &" " '
5
2644
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 here And this came out, via prettify: <addresssnippet siteurl="http%3A//apartmentsapart.com"...
3
2186
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 disappears into never-never land. LONG VERSION: I am working on a site that can kick off large-scale simulations. It will write the output to...
0
7806
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8056
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8239
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6455
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5301
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3741
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3752
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2247
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.