1

I am having an issue with executing a perl script from php using the shell_exec() function.

This is what I have tried (and it has worked before).

$perl = shell_exec("/usr/bin/perl cbh_script_clean.pl");
echo ($perl);

This will not work as $perl does not contain anything after this is executed.

Thoughts?

All help is appreciated!

Thanks.

jmg0880
  • 115
  • 1
  • 8
  • 19
  • What happens when you run `/usr/bin/perl cbh_script_clean.pl` straight from the command line? – webbiedave May 11 '11 at 23:06
  • But what happens? What do you see on the screen after you run the command? – webbiedave May 11 '11 at 23:08
  • Try adding `2>&1` after the command. Chances are the pathname to the perl script is just wrong. Also have a look into the error.log, which otherwise contains the according message. – mario May 11 '11 at 23:11
  • @webbie: the script is run fully. it successfully runs the script – jmg0880 May 11 '11 at 23:11
  • @mario: what exactly does that do? – jmg0880 May 11 '11 at 23:12
  • ahhhh it tells me there is a permissions error. i was creating 2 logs in order to troubleshoot with the Net::Telnet:Cisco module and i didnt have them set for full permissions – jmg0880 May 11 '11 at 23:14
  • What it does is: telling you that there was a permissions error. :) – mario May 11 '11 at 23:17

2 Answers2

7

I'll make that an answer then.

You can often append 2>&1 to redirect the stderr output to the normal stdout stream. This way you receive any error messages in the PHP variable. (Otherwise they will get lost with system/exec/shell_exec, which is why people sometimes use proc_open with explicit pipes instead).

$perl = shell_exec("/usr/bin/perl cbh_script_clean.pl 2>&1");
echo ($perl);
mario
  • 144,265
  • 20
  • 237
  • 291
1

Try this:

$perl = shell_exec("/usr/bin/perl cbh_script_clean.pl 2>/dev/null >/dev/null &"); echo ($perl);