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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rickcasey

    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,$myou tput,$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

  • Justin Koivisto

    #2
    Re: cannot get exec() or passthru() to work?

    rickcasey wrote:[color=blue]
    > 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,$myou tput,$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![/color]

    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 - justin@koivi.co m

    Comment

    • Peter van Schie

      #3
      Re: cannot get exec() or passthru() to work?

      rickcasey wrote:
      [color=blue]
      > rtnvar = 13[/color]

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

      Comment

      Working...