0

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.

1

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.