468,140 Members | 1,431 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,140 developers. It's quick & easy.

cannot get exec() or passthru() to work?

I cannnot seem to get exec() or passthru() to execute a perl script;
here's the code snippet:

if ($debug) {
echo "username1 = ".$username1."<br>";
echo "dbname = ".$dbname."<br>";
echo "SESSION[dbname] = ".$_SESSION['dbname']."<br>";
echo "Output file = ".$outputfile."<br>";
echo "Project name = ".$projectname."<br>";
echo "Study name = ".$studyname."<br>";
echo "The command to be run is: ".$cmd."<br>";
}

// Run the command!
exec($cmd,$myoutput,$rtnvar);
echo "rtnvar = ".$rtnvar."<br>";

foreach ($myoutput as $line) {
echo $line."<br>";
}

Which produces the results:

username1 = rick
dbname = cgb_lab_data
SESSION[dbname] = cgb_lab_data
Output file = myoutput
Project name = IBS11_1103
Study name = IBS 11
The command to be run is: perl
/home/caseyr/projects/LIMSScripts/3100DataIO/mk3100plt.pl -n 'IBS 11'
-b 1103 -o myoutput -p IBS11_1103 -i S
rtnvar = 13
The command looks perfectly legit, and will run at the command line if
I cut and paste it.

I do not understand the return value of 13.

I can get a simple perl script that takes no arguments to run ok; so I
think this has something to do with the arguments. I've used
escapeshellarg() to no avail. I've always tried the same with system()
and the backtick operator -- nada!

If anyone can spot what I might be doing wrong, I'd appreciate it!

Rick

Nov 1 '05 #1
2 1567
rickcasey wrote:
I cannnot seem to get exec() or passthru() to execute a perl script;
here's the code snippet:

if ($debug) {
echo "username1 = ".$username1."<br>";
echo "dbname = ".$dbname."<br>";
echo "SESSION[dbname] = ".$_SESSION['dbname']."<br>";
echo "Output file = ".$outputfile."<br>";
echo "Project name = ".$projectname."<br>";
echo "Study name = ".$studyname."<br>";
echo "The command to be run is: ".$cmd."<br>";
}

// Run the command!
exec($cmd,$myoutput,$rtnvar);
echo "rtnvar = ".$rtnvar."<br>";

foreach ($myoutput as $line) {
echo $line."<br>";
}

Which produces the results:

username1 = rick
dbname = cgb_lab_data
SESSION[dbname] = cgb_lab_data
Output file = myoutput
Project name = IBS11_1103
Study name = IBS 11
The command to be run is: perl
/home/caseyr/projects/LIMSScripts/3100DataIO/mk3100plt.pl -n 'IBS 11'
-b 1103 -o myoutput -p IBS11_1103 -i S
rtnvar = 13

The command looks perfectly legit, and will run at the command line if
I cut and paste it.

I do not understand the return value of 13.

I can get a simple perl script that takes no arguments to run ok; so I
think this has something to do with the arguments. I've used
escapeshellarg() to no avail. I've always tried the same with system()
and the backtick operator -- nada!

If anyone can spot what I might be doing wrong, I'd appreciate it!


First I'd try changing the single quote to double quotes: "IBS 11"

....as well as providing the full system path to the perl executable.
(run "which perl" to find it on the system).

You may also want to check that there aren't any extra control
characters like tab or newline in the command variable just in case...

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Nov 1 '05 #2
rickcasey wrote:
rtnvar = 13


Hi Rick,

I see that the return value is 13. On Linux error 13 means:

13 (EACCES) - Permission denied

So the webserver user probably doesn't have the permission to execute perl.

HTH.
Peter.
--
http://www.phpforums.nl
Nov 1 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jerry | last post: by
17 posts views Thread by Piotr Wolski | last post: by
14 posts views Thread by Hemanth | last post: by
2 posts views Thread by Greg Chapman | last post: by
4 posts views Thread by Tom | last post: by
1 post views Thread by rickcasey | last post: by
3 posts views Thread by dinek | last post: by
27 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.