3

I have a python script that runs a TCP server and is running indefinitely. This script is working on background in my terminal:

sudo python3 TCPServer.py &

But when I use PHP shell_exec command:

shell_exec('sudo python3 TCPServer.py &')

It executes but waits forever. I want it to run on background.

1 Answer 1

1

To run a command in background with shell_exec, the output must be redirected to /dev/null. Refer the php nanual notes.

shell_exec("python3 TCPServer.py 2>&1 | tee -a /tmp/mylog 2>/dev/null >/dev/null &");
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! What I was looking for. :)

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.