@@ -120,23 +120,21 @@ however, `.bat` and `.cmd` files are not executable on their own without a
120120terminal, and therefore cannot be launched using [ ` child_process.execFile() ` ] [ ] .
121121When running on Windows, ` .bat ` and ` .cmd ` files can be invoked by:
122122
123- * using [ ` child_process.spawn() ` ] [ ] with the ` shell ` option set, or
124123* using [ ` child_process.exec() ` ] [ ] , or
125124* spawning ` cmd.exe ` and passing the ` .bat ` or ` .cmd ` file as an argument
126- (which is what the ` shell ` option and [ ` child_process.exec() ` ] [ ] do ).
125+ (which is what [ ` child_process.exec() ` ] [ ] does internally ).
127126
128127In any case, if the script filename contains spaces, it needs to be quoted.
129128
129+ Using [ ` child_process.spawn() ` ] [ ] with the ` shell ` option is not recommended
130+ because passing arguments that way is deprecated ([ DEP0190] [ ] ).
131+
130132``` cjs
131133const { exec , spawn } = require (' node:child_process' );
132134
133- // 1. child_process.spawn() with the shell option set
134- const myBat = spawn (' my.bat' , { shell: true });
135-
136- // 2. child_process.exec()
137135exec (' my.bat' , (err , stdout , stderr ) => { /* ... */ });
138136
139- // 3. spawning cmd.exe and passing the .bat or .cmd file as an argument
137+ // Or, spawning cmd.exe directly:
140138const bat = spawn (' cmd.exe' , [' /c' , ' my.bat' ]);
141139
142140// If the script filename contains spaces, it needs to be quoted
@@ -146,13 +144,9 @@ exec('"my script.cmd" a b', (err, stdout, stderr) => { /* ... */ });
146144``` mjs
147145import { exec , spawn } from ' node:child_process' ;
148146
149- // 1. child_process.spawn() with the shell option set
150- const myBat = spawn (' my.bat' , { shell: true });
151-
152- // 2. child_process.exec()
153147exec (' my.bat' , (err , stdout , stderr ) => { /* ... */ });
154148
155- // 3. spawning cmd.exe and passing the .bat or .cmd file as an argument
149+ // Or, spawning cmd.exe directly:
156150const bat = spawn (' cmd.exe' , [' /c' , ' my.bat' ]);
157151
158152// If the script filename contains spaces, it needs to be quoted
@@ -2364,6 +2358,7 @@ Therefore, this feature requires opting in by setting the
23642358or [`child_process.fork()`][].
23652359
23662360[Advanced serialization]: #advanced-serialization
2361+ [DEP0190]: deprecations.md#dep0190-passing-args-to-nodechild_process-execfilespawn-with-shell-option-true
23672362[Default Windows shell]: #default-windows-shell
23682363[HTML structured clone algorithm]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm
23692364[Shell requirements]: #shell-requirements
0 commit comments