To decide which program should execute a file:
- Unix uses shebangs like
#!/usr/bin/node
. - Windows uses filename extensions.
Cross-platform file execution must either:
- explicitly specify the program, e.g.
node ./file.js
instead of./file.js
. - use
execa
which polyfills shebangs on Windows. - use
open
.
During file execution the extension can be omitted on Windows if it is listed in
the
PATHEXT
environment variable, which defaults to
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
. This won't work on
Unix.
The PATH
environment
variable uses ;
instead of :
as delimiter on Windows. This can be retrieved
with path.delimiter
.
When the option
detached: false
of
child_process.spawn()
is used, the child process will be terminated when its parent is on Windows, but
not on Unix.
When the option
detached: true
is used instead, a new terminal window will appear on Windows unless the option
windowsHide: true
is used (requires Node >= 8.8.0
).
Finally the option
argv0
does not modify process.title
on Windows.
Redirecting to a file descriptor with the
stdio
option
of
child_process.spawn()
is
not supported on Windows.
Many of those differences can be solved by using
execa
.
Fire shell commands with execa
.