Skip to content

Commit 4a8aca7

Browse files
bzozevanlucas
authored andcommitted
doc: script with spaces spawn example for windows
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>
1 parent 4f09886 commit 4a8aca7

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

doc/api/child_process.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ be launched using [`child_process.execFile()`][]. When running on Windows, `.bat
8282
and `.cmd` files can be invoked using [`child_process.spawn()`][] with the `shell`
8383
option set, with [`child_process.exec()`][], or by spawning `cmd.exe` and passing
8484
the `.bat` or `.cmd` file as an argument (which is what the `shell` option and
85-
[`child_process.exec()`][] do).
85+
[`child_process.exec()`][] do). In any case, if the script filename contains
86+
spaces it needs to be quoted.
8687

8788
```js
8889
// On Windows Only ...
@@ -110,6 +111,13 @@ exec('my.bat', (err, stdout, stderr) => {
110111
}
111112
console.log(stdout);
112113
});
114+
115+
// Script with spaces in the filename:
116+
const bat = spawn('"my script.cmd"', ['a', 'b'], { shell:true });
117+
// or:
118+
exec('"my script.cmd" a b', (err, stdout, stderr) => {
119+
// ...
120+
});
113121
```
114122

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

0 commit comments

Comments
 (0)