Oyeme
Oyeme

Reputation: 11225

Php shell_exec return running process ID


I'm trying to return a process ID throw a php. In Linux this command return Process ID

/receive.sh url=http://www.site.com cert=certs/test_lv.p12?test_lv > /dev/null 2>/dev/null &

I need to run this command throw a php.

$response2 = shell_exec("./receive.sh url=https://www.site.com cert=certs/test.p12?test_lv  > /dev/null 2>/dev/null &");
 echo $response2;

It's returned an empty string. Thanks for answers!

Updated* I added an ouput PID and it works! Thanks to all!

./receive.sh url=https://www.site.com cert=certs/test_lv.p12?test_lv  > /dev/null 2>/dev/null &  echo $!

Upvotes: 0

Views: 2795

Answers (3)

Master_ex
Master_ex

Reputation: 779

shell_exec returns the output stream. Your command may print the process id to the error stream and that's why you get an empty string.

Here you can see how to print the error stream. I am not sure if that's your case but give it a try.

Upvotes: 1

Muhannad A.Alhariri
Muhannad A.Alhariri

Reputation: 3912

I think you code has a bug since it already redirects the output to /dev/null in your command , just try to remove the output redirection and it may work

Upvotes: 1

spraff
spraff

Reputation: 33395

Check out popen.

Upvotes: -1

Related Questions