View source code
Display the source code in std/process.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Function std.process.spawnShell

A variation on spawnProcess that runs the given command through the current user's preferred command interpreter (aka. shell).

Pid spawnShell (
  scope const(char)[] command,
  File stdin = makeGlobal(),
  File stdout = makeGlobal(),
  File stderr = makeGlobal(),
  scope const(string[string]) env = cast(const(string[string]))null,
  Config config = Config(Flags.none, null, null),
  scope const(char)[] workDir = null,
  scope string shellPath = nativeShell()
) @trusted;

Pid spawnShell (
  scope const(char)[] command,
  scope const(string[string]) env,
  Config config = Config(Flags.none, null, null),
  scope const(char)[] workDir = null,
  scope string shellPath = nativeShell()
) @trusted;

The string command is passed verbatim to the shell, and is therefore subject to its rules about command structure, argument/filename quoting and escaping of special characters. The path to the shell executable defaults to nativeShell.

In all other respects this function works just like spawnProcess. Please refer to the spawnProcess documentation for descriptions of the other function parameters, the return value and any exceptions that may be thrown.

// Run the command/program "foo" on the file named "my file.txt", and
// redirect its output into foo.log.
auto pid = spawnShell(`foo "my file.txt" > foo.log`);
wait(pid);

See also

escapeShellCommand, which may be helpful in constructing a properly quoted and escaped shell command line for the current platform.

Authors

Lars Tandle Kyllingstad, Steven Schveighoffer, Vladimir Panteleev

License

Boost License 1.0.