简体   繁体   中英

using shell_exec to call a perl script from php

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.

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);

Try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM