๐Ÿ’ป File execution

June 2, 2024 ยท View on GitHub

Program selection

To decide which program should execute a file:

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.

File extensions

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.

PATH variable

The PATH environment variable uses ; instead of : as delimiter on Windows. This can be retrieved with path.delimiter.

child_process.spawn()

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.

Summary

Fire shell commands with execa.


Next (๐Ÿ’ป Package binaries)
Previous (๐Ÿ’ป Shell)
Top