0

I call a python script from PHP but i run script in background because i don't want to wait after script to finish, so i use > /dev/null 2>/dev/null & with shell_exec.
This is the code where i call:

shell_exec("C:\\Python27\\python C:\\xampp\\htdocs\\testing.py > /dev/null 2>/dev/null &");

in python script i have a simple write file:

fileName = "temp.txt"
target = open(fileName, 'w')

for x in range(1, 59):
    target.write("test" + str(x) + "
")

target.close()

When i call script from PHP with shell_exec("C:\\Python27\\python C:\\xampp\\htdocs\\testing.py");
it's working but webpage it's waiting after script to finish and i don't want that, so i called with > /dev/null 2>/dev/null & but now, the code doesn't run.
Any ideas why code doesn't working when i want to run in background?
Thanks!

LE:

Changed /dev/null/ with nul and still no working.
Now i call shell_exec("C:\\Python27\\python C:\\xampp\\htdocs\\testing.py > NUL 2> NUL &"); and it's working but page still wating after script to finish.

6
  • possible duplicate of /dev/null in Windows? Commented Aug 20, 2015 at 11:19
  • No, still not working with nul and not /dev/null Commented Aug 20, 2015 at 11:24
  • It is NUL, not nul. /dev/null is a Linux bit bucket, and C:\\... is a Windows path... you cannot mix and match Linux and Windows paths like this. Commented Aug 20, 2015 at 11:55
  • I tried with both options, still no work... It's working but it's waiting after script to finish. Commented Aug 20, 2015 at 11:56
  • Well, the entire > NUL 2> NUL & is a Linux command (with the Win bit bucket). As I said, you cannot mix and match Linux and Windows stuff like this. Outputting stuff to NUL would just be ... > NUL. According to this, background processes are run using START /B [PATH_TO_EXEC]. Do some research before asking more questions. Commented Aug 20, 2015 at 13:08

1 Answer 1

1

The answer is:
pclose(popen("start /B ". $cmd, "r"));
You can start a program without cmd and PHP will not wait after program to finish.

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

Comments

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.