hedgehog90 hedgehog90 - 1 month ago 4x
PHP Question

START /B with php/node/python script doesn't work as expected

I start a shell and I run the following command:

START "" /B php test.php>nul 2>&1

For the purposes of this post, test.php consists of 1 line: file_put_contents("test", "test");

You'd expect it to instantly create a file called test, however it doesn't.
Instead, when I enter the command and hit enter, nothing happens. However, in the same command window, if I hit the enter key once more, the script will run.

I've tried the equivalent command with node, python2 and python3. They all do the same thing, although python3 oiddly enough requires 2 enter key presses before the script is run.

This appears to be a quirk when running START /B with script interpreters. If I ran START /B with an .exe or .bat then it runs as expected.

Now, obviously I don't need to run a background process that creates a file named 'test'. What I need it to do is to start a daemon process written in php and a daemon process written in nodejs, one after the other in the same terminal.

I've also noticed if I write these commands to a batch file and run them by double clicking the batch file instead of calling it from the shell, then it all runs as expected.

Please help. I've been wrestling with this problem for 2 days now.


I've just found that this problem is unique to my computer, running on Windows 10. I tried on Windows 7 and Windows XP and they did not require extra return inputs from me to run the script...

I've just tried booting up in safe mode and clearing my path variables. Still it persists.
I wonder if this is a bug/feature of Windows 10?
How the hell do I diagnose and fix this?


Just tested the same script on a Windows 8 machine, which unexpectedly does exactly what my Windows 10 machine does. SO it looks like only Windows 8 and Windows 10 have this problem... And using legacy mode makes no difference.
What the FFFFFFFFFnnngggghhhrrr... I can't find anyone reporting this issue anywhere.

Here's a gif animation of exactly what happens:

enter image description here

Proof that the script is only run on the second return key press.


You could try <NUL to send an additional Enter to the command.

start "" /b php test.php <NUL

Re: why this happens, sorry, I couldn't answer that part. Bug? Security? Undocumented feature? *shrug*