deepwiki-lab
Relevant source files
  • docs/shell.md
  • docs/windows.md
  • docs/bash.md
  • docs/small.md
  • docs/scripts.md
  • docs/bash.md
  • test-d/arguments/env.test-d.ts

Execa Documentation: Windows

Overview

Execa is a Node.js library that provides a cross-platform way to run commands and interact with the operating system. While it can be used on any platform, there are some specific considerations when using it on Windows.

Avoiding Shells

On Windows, a shell is often used to work around limitations of the OS. However, with Execa, you don't need to use a shell to run .cmd and .bat files, resolve a command by name using PATHEXT, run shebang scripts, or escape file paths and arguments.

Specific Shell

If you need to use a specific shell, you can pass the shell path to the execa function. For example:

import {execa} from 'execa';

await execa({shell: '/bin/bash'})`npm run "$TASK" && npm run test`;

OS-Specific Shell

When the shell option is true, sh is used on Unix and cmd.exe is used on Windows. However, this is usually not useful due to the different syntaxes of sh and cmd.exe.

Shebang

On Unix, executable files can use shebangs. Although Windows does not natively support shebangs, Execa adds support for them. This means you can run shebang scripts on Windows without needing to use a shell.

File Extensions

On Windows, executables have a file extension, such as .exe, .cmd, .bat or .com. When the file is passed without any extension, Execa resolves it using the PATHEXT environment variable, just like the OS does when looking up commands.

Signals

Only a few signals work on Windows with Node.js: SIGTERM, SIGKILL, SIGINT, and SIGQUIT. Sending signals from other processes is not supported. The forceKillAfterDelay option is a noop on Windows.

Asynchronous I/O

The default value for the stdin, stdout, and stderr options is 'pipe'. This returns the output as result.stdout and result.stderr and allows for manual streaming. Instead of 'pipe', 'overlapped' can be used to use asynchronous I/O under-the-hood on Windows.

Escaping

Windows requires files and arguments to be quoted when they contain spaces, tabs, backslashes, or double quotes. Unlike Unix, this is needed even when no shell is used. Execa performs this quoting automatically when not using a shell.

Console Window

If the windowsHide option is false, the subprocess is run in a new console window. This is necessary to make SIGINT work on Windows and to clean up subprocesses which spawn their own subprocesses.

UID and GID

By default, subprocesses are run using the current user and group. The uid and gid options can be used to set a different user or group. However, since Windows uses a different permission model, those options throw.

graph TD

A[Execa] B[Windows] C[Shebang] D[File Extensions] E[Signals] F[Asynchronous I/O] G[Escaping] H[Console Window] I[UID and GID] A-->B B-->C B-->D B-->E B-->F B-->G B-->H B-->I

Sources: docs/shell.md docs/windows.md docs/bash.md docs/small.md docs/scripts.md docs/bash.md test-d/arguments/env.test-d.ts