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.

7
  • What happens when you run /usr/bin/perl cbh_script_clean.pl straight from the command line? Commented May 11, 2011 at 23:06
  • But what happens? What do you see on the screen after you run the command? Commented May 11, 2011 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. Commented May 11, 2011 at 23:11
  • @webbie: the script is run fully. it successfully runs the script Commented May 11, 2011 at 23:11
  • @mario: what exactly does that do? Commented May 11, 2011 at 23:12

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.