473,883 Members | 2,049 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 10356
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
1657
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
20549
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
14824
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
3451
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
6872
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 format so that I can use this xml for another use. Please help! <NewDataSet> <Table1>
3
3108
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
2668
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" url="http%3A//www.apartmentsapart.com/Europe/Spain/Madrid/FAQ"> <param name="movie" value="/images/offersBanners/sw04.swf?binfot=We offer
3
2204
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 an html file and a link will be emailed to the user. Also, the site will continue to display...
0
11157
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10763
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10863
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10422
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9586
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7136
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4622
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
2
4229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3241
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.