Simone Sessa
Simone Sessa

Reputation: 873

Kill process with php command

In ubuntu terminal, I can kill "firefox" with this comand: pgrep python | xargs kill and it works.

But if I try to execute this comand in php in localhost, with this code: exec("sudo pgrep firefox | xargs kill",$output); It doesn't work and the output is an empty array. I've just added "www-data" in sudoers. Other exec comand work.

Upvotes: 0

Views: 629

Answers (1)

A.Raudner
A.Raudner

Reputation: 71

For sudo to work You CAN'T have a pipe "|" within the call tha way.

Also the clean way is to write the whole path to a binary, like "/usr/bin/pgrep"

Best way to handle redirections in sudo is to put the whole command in a script and sudo that.

Upvotes: 1

Related Questions