Skip to content

Commit

Permalink
doc: script with spaces spawn example for windows
Browse files Browse the repository at this point in the history
Adds an example of how to spawn a shell script under Windows with
spaces in its filename.

Ref: #7367
PR-URL: #8035
Reviewed-By: João Reis <reis@janeasystems.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
bzoz authored and jasnell committed Aug 18, 2016
1 parent 5f617c5 commit 0abdf59
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion doc/api/child_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ be launched using [`child_process.execFile()`][]. When running on Windows, `.bat
and `.cmd` files can be invoked using [`child_process.spawn()`][] with the `shell`
option set, with [`child_process.exec()`][], or by spawning `cmd.exe` and passing
the `.bat` or `.cmd` file as an argument (which is what the `shell` option and
[`child_process.exec()`][] do).
[`child_process.exec()`][] do). In any case, if the script filename contains
spaces it needs to be quoted.

```js
// On Windows Only ...
Expand Down Expand Up @@ -110,6 +111,13 @@ exec('my.bat', (err, stdout, stderr) => {
}
console.log(stdout);
});

// Script with spaces in the filename:
const bat = spawn('"my script.cmd"', ['a', 'b'], { shell:true });
// or:
exec('"my script.cmd" a b', (err, stdout, stderr) => {
// ...
});
```

### child_process.exec(command[, options][, callback])
Expand Down

0 comments on commit 0abdf59

Please sign in to comment.