What are the differences between running a process with and without a shell?

Viewed 329

In the Node.js docs for child_process, I came upon this line:

Since a shell is not spawned, behaviors such as I/O redirection and file globbing are not supported.

That’s good to know, but the “such as” worries me. What other behaviors are missing? What even counts as running without a shell — isn’t sh/cmd.exe still parsing the command-line input?

1 Answers

It looks like my initial assumption was flawed: neither the Bourne shell (sh) nor Windows’s cmd.exe parses the command when invoked without a shell — it’s up to the consuming application to do so.

The most significant lost feature is the lack of filename expansion. Unless the called application binary understands UNIX file syntax, you can’t do most relative file path tricks:

  • No ../ for a parent directory
  • No ./ for the current working directory
  • No ~ for the user directory

Other shell syntax characters like redirection operators (> for example) and pipes (|) are unsupported.

Basically, if it’s listed as a feature on the shell’s wikipedia page, non-shell execution won’t have it.

Related