-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchild_process.json
1459 lines (1459 loc) · 117 KB
/
child_process.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"type": "module",
"source": "doc/api/child_process.md",
"modules": [
{
"textRaw": "Child Process",
"name": "child_process",
"introduced_in": "v0.10.0",
"desc": "<!--lint disable maximum-line-length-->\n<blockquote>\n<p>Stability: 2 - Stable</p>\n</blockquote>\n<p>The <code>child_process</code> module provides the ability to spawn child processes in\na manner that is similar, but not identical, to <a href=\"http://man7.org/linux/man-pages/man3/popen.3.html\"><code>popen(3)</code></a>. This capability\nis primarily provided by the <a href=\"#child_process_child_process_spawn_command_args_options\"><code>child_process.spawn()</code></a> function:</p>\n<pre><code class=\"language-js\">const { spawn } = require('child_process');\nconst ls = spawn('ls', ['-lh', '/usr']);\n\nls.stdout.on('data', (data) => {\n console.log(`stdout: ${data}`);\n});\n\nls.stderr.on('data', (data) => {\n console.log(`stderr: ${data}`);\n});\n\nls.on('close', (code) => {\n console.log(`child process exited with code ${code}`);\n});\n</code></pre>\n<p>By default, pipes for <code>stdin</code>, <code>stdout</code>, and <code>stderr</code> are established between\nthe parent Node.js process and the spawned child. These pipes have\nlimited (and platform-specific) capacity. If the child process writes to\nstdout in excess of that limit without the output being captured, the child\nprocess will block waiting for the pipe buffer to accept more data. This is\nidentical to the behavior of pipes in the shell. Use the <code>{ stdio: 'ignore' }</code>\noption if the output will not be consumed.</p>\n<p>The <a href=\"#child_process_child_process_spawn_command_args_options\"><code>child_process.spawn()</code></a> method spawns the child process asynchronously,\nwithout blocking the Node.js event loop. The <a href=\"#child_process_child_process_spawnsync_command_args_options\"><code>child_process.spawnSync()</code></a>\nfunction provides equivalent functionality in a synchronous manner that blocks\nthe event loop until the spawned process either exits or is terminated.</p>\n<p>For convenience, the <code>child_process</code> module provides a handful of synchronous\nand asynchronous alternatives to <a href=\"#child_process_child_process_spawn_command_args_options\"><code>child_process.spawn()</code></a> and\n<a href=\"#child_process_child_process_spawnsync_command_args_options\"><code>child_process.spawnSync()</code></a>. <em>Note that each of these alternatives are\nimplemented on top of <a href=\"#child_process_child_process_spawn_command_args_options\"><code>child_process.spawn()</code></a> or <a href=\"#child_process_child_process_spawnsync_command_args_options\"><code>child_process.spawnSync()</code></a>.</em></p>\n<ul>\n<li><a href=\"#child_process_child_process_exec_command_options_callback\"><code>child_process.exec()</code></a>: spawns a shell and runs a command within that shell,\npassing the <code>stdout</code> and <code>stderr</code> to a callback function when complete.</li>\n<li><a href=\"#child_process_child_process_execfile_file_args_options_callback\"><code>child_process.execFile()</code></a>: similar to <a href=\"#child_process_child_process_exec_command_options_callback\"><code>child_process.exec()</code></a> except that\nit spawns the command directly without first spawning a shell by default.</li>\n<li><a href=\"#child_process_child_process_fork_modulepath_args_options\"><code>child_process.fork()</code></a>: spawns a new Node.js process and invokes a\nspecified module with an IPC communication channel established that allows\nsending messages between parent and child.</li>\n<li><a href=\"#child_process_child_process_execsync_command_options\"><code>child_process.execSync()</code></a>: a synchronous version of\n<a href=\"#child_process_child_process_exec_command_options_callback\"><code>child_process.exec()</code></a> that <em>will</em> block the Node.js event loop.</li>\n<li><a href=\"#child_process_child_process_execfilesync_file_args_options\"><code>child_process.execFileSync()</code></a>: a synchronous version of\n<a href=\"#child_process_child_process_execfile_file_args_options_callback\"><code>child_process.execFile()</code></a> that <em>will</em> block the Node.js event loop.</li>\n</ul>\n<p>For certain use cases, such as automating shell scripts, the\n<a href=\"#child_process_synchronous_process_creation\">synchronous counterparts</a> may be more convenient. In many cases, however,\nthe synchronous methods can have significant impact on performance due to\nstalling the event loop while spawned processes complete.</p>",
"modules": [
{
"textRaw": "Asynchronous Process Creation",
"name": "asynchronous_process_creation",
"desc": "<p>The <a href=\"#child_process_child_process_spawn_command_args_options\"><code>child_process.spawn()</code></a>, <a href=\"#child_process_child_process_fork_modulepath_args_options\"><code>child_process.fork()</code></a>, <a href=\"#child_process_child_process_exec_command_options_callback\"><code>child_process.exec()</code></a>,\nand <a href=\"#child_process_child_process_execfile_file_args_options_callback\"><code>child_process.execFile()</code></a> methods all follow the idiomatic asynchronous\nprogramming pattern typical of other Node.js APIs.</p>\n<p>Each of the methods returns a <a href=\"#child_process_child_process\"><code>ChildProcess</code></a> instance. These objects\nimplement the Node.js <a href=\"events.html#events_class_eventemitter\"><code>EventEmitter</code></a> API, allowing the parent process to\nregister listener functions that are called when certain events occur during\nthe life cycle of the child process.</p>\n<p>The <a href=\"#child_process_child_process_exec_command_options_callback\"><code>child_process.exec()</code></a> and <a href=\"#child_process_child_process_execfile_file_args_options_callback\"><code>child_process.execFile()</code></a> methods additionally\nallow for an optional <code>callback</code> function to be specified that is invoked\nwhen the child process terminates.</p>",
"modules": [
{
"textRaw": "Spawning `.bat` and `.cmd` files on Windows",
"name": "spawning_`.bat`_and_`.cmd`_files_on_windows",
"desc": "<p>The importance of the distinction between <a href=\"#child_process_child_process_exec_command_options_callback\"><code>child_process.exec()</code></a> and\n<a href=\"#child_process_child_process_execfile_file_args_options_callback\"><code>child_process.execFile()</code></a> can vary based on platform. On Unix-type operating\nsystems (Unix, Linux, macOS) <a href=\"#child_process_child_process_execfile_file_args_options_callback\"><code>child_process.execFile()</code></a> can be more efficient\nbecause it does not spawn a shell by default. On Windows, however, <code>.bat</code> and <code>.cmd</code>\nfiles are not executable on their own without a terminal, and therefore cannot\nbe launched using <a href=\"#child_process_child_process_execfile_file_args_options_callback\"><code>child_process.execFile()</code></a>. When running on Windows, <code>.bat</code>\nand <code>.cmd</code> files can be invoked using <a href=\"#child_process_child_process_spawn_command_args_options\"><code>child_process.spawn()</code></a> with the <code>shell</code>\noption set, with <a href=\"#child_process_child_process_exec_command_options_callback\"><code>child_process.exec()</code></a>, or by spawning <code>cmd.exe</code> and passing\nthe <code>.bat</code> or <code>.cmd</code> file as an argument (which is what the <code>shell</code> option and\n<a href=\"#child_process_child_process_exec_command_options_callback\"><code>child_process.exec()</code></a> do). In any case, if the script filename contains\nspaces it needs to be quoted.</p>\n<pre><code class=\"language-js\">// On Windows Only ...\nconst { spawn } = require('child_process');\nconst bat = spawn('cmd.exe', ['/c', 'my.bat']);\n\nbat.stdout.on('data', (data) => {\n console.log(data.toString());\n});\n\nbat.stderr.on('data', (data) => {\n console.log(data.toString());\n});\n\nbat.on('exit', (code) => {\n console.log(`Child exited with code ${code}`);\n});\n</code></pre>\n<pre><code class=\"language-js\">// OR...\nconst { exec } = require('child_process');\nexec('my.bat', (err, stdout, stderr) => {\n if (err) {\n console.error(err);\n return;\n }\n console.log(stdout);\n});\n\n// Script with spaces in the filename:\nconst bat = spawn('\"my script.cmd\"', ['a', 'b'], { shell: true });\n// or:\nexec('\"my script.cmd\" a b', (err, stdout, stderr) => {\n // ...\n});\n</code></pre>",
"type": "module",
"displayName": "Spawning `.bat` and `.cmd` files on Windows"
}
],
"methods": [
{
"textRaw": "child_process.exec(command[, options][, callback])",
"type": "method",
"name": "exec",
"meta": {
"added": [
"v0.1.90"
],
"changes": [
{
"version": "v8.8.0",
"pr-url": "https://github.com/nodejs/node/pull/15380",
"description": "The `windowsHide` option is supported now."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {ChildProcess}",
"name": "return",
"type": "ChildProcess"
},
"params": [
{
"textRaw": "`command` {string} The command to run, with space-separated arguments.",
"name": "command",
"type": "string",
"desc": "The command to run, with space-separated arguments."
},
{
"textRaw": "`options` {Object}",
"name": "options",
"type": "Object",
"options": [
{
"textRaw": "`cwd` {string} Current working directory of the child process. **Default:** `null`.",
"name": "cwd",
"type": "string",
"default": "`null`",
"desc": "Current working directory of the child process."
},
{
"textRaw": "`env` {Object} Environment key-value pairs. **Default:** `null`.",
"name": "env",
"type": "Object",
"default": "`null`",
"desc": "Environment key-value pairs."
},
{
"textRaw": "`encoding` {string} **Default:** `'utf8'`",
"name": "encoding",
"type": "string",
"default": "`'utf8'`"
},
{
"textRaw": "`shell` {string} Shell to execute the command with. See [Shell Requirements][] and [Default Windows Shell][]. **Default:** `'/bin/sh'` on UNIX, `process.env.ComSpec` on Windows.",
"name": "shell",
"type": "string",
"default": "`'/bin/sh'` on UNIX, `process.env.ComSpec` on Windows",
"desc": "Shell to execute the command with. See [Shell Requirements][] and [Default Windows Shell][]."
},
{
"textRaw": "`timeout` {number} **Default:** `0`",
"name": "timeout",
"type": "number",
"default": "`0`"
},
{
"textRaw": "`maxBuffer` {number} Largest amount of data in bytes allowed on stdout or stderr. If exceeded, the child process is terminated. See caveat at [`maxBuffer` and Unicode][]. **Default:** `200 * 1024`.",
"name": "maxBuffer",
"type": "number",
"default": "`200 * 1024`",
"desc": "Largest amount of data in bytes allowed on stdout or stderr. If exceeded, the child process is terminated. See caveat at [`maxBuffer` and Unicode][]."
},
{
"textRaw": "`killSignal` {string|integer} **Default:** `'SIGTERM'`",
"name": "killSignal",
"type": "string|integer",
"default": "`'SIGTERM'`"
},
{
"textRaw": "`uid` {number} Sets the user identity of the process (see setuid(2)).",
"name": "uid",
"type": "number",
"desc": "Sets the user identity of the process (see setuid(2))."
},
{
"textRaw": "`gid` {number} Sets the group identity of the process (see setgid(2)).",
"name": "gid",
"type": "number",
"desc": "Sets the group identity of the process (see setgid(2))."
},
{
"textRaw": "`windowsHide` {boolean} Hide the subprocess console window that would normally be created on Windows systems. **Default:** `false`.",
"name": "windowsHide",
"type": "boolean",
"default": "`false`",
"desc": "Hide the subprocess console window that would normally be created on Windows systems."
}
],
"optional": true
},
{
"textRaw": "`callback` {Function} called with the output when process terminates.",
"name": "callback",
"type": "Function",
"desc": "called with the output when process terminates.",
"options": [
{
"textRaw": "`error` {Error}",
"name": "error",
"type": "Error"
},
{
"textRaw": "`stdout` {string|Buffer}",
"name": "stdout",
"type": "string|Buffer"
},
{
"textRaw": "`stderr` {string|Buffer}",
"name": "stderr",
"type": "string|Buffer"
}
],
"optional": true
}
]
}
],
"desc": "<p>Spawns a shell then executes the <code>command</code> within that shell, buffering any\ngenerated output. The <code>command</code> string passed to the exec function is processed\ndirectly by the shell and special characters (vary based on\n<a href=\"https://en.wikipedia.org/wiki/List_of_command-line_interpreters\">shell</a>)\nneed to be dealt with accordingly:</p>\n<pre><code class=\"language-js\">exec('\"/path/to/test file/test.sh\" arg1 arg2');\n// Double quotes are used so that the space in the path is not interpreted as\n// multiple arguments\n\nexec('echo \"The \\\\$HOME variable is $HOME\"');\n// The $HOME variable is escaped in the first instance, but not in the second\n</code></pre>\n<p><strong>Never pass unsanitized user input to this function. Any input containing shell\nmetacharacters may be used to trigger arbitrary command execution.</strong></p>\n<p>If a <code>callback</code> function is provided, it is called with the arguments\n<code>(error, stdout, stderr)</code>. On success, <code>error</code> will be <code>null</code>. On error,\n<code>error</code> will be an instance of <a href=\"errors.html#errors_class_error\"><code>Error</code></a>. The <code>error.code</code> property will be\nthe exit code of the child process while <code>error.signal</code> will be set to the\nsignal that terminated the process. Any exit code other than <code>0</code> is considered\nto be an error.</p>\n<p>The <code>stdout</code> and <code>stderr</code> arguments passed to the callback will contain the\nstdout and stderr output of the child process. By default, Node.js will decode\nthe output as UTF-8 and pass strings to the callback. The <code>encoding</code> option\ncan be used to specify the character encoding used to decode the stdout and\nstderr output. If <code>encoding</code> is <code>'buffer'</code>, or an unrecognized character\nencoding, <code>Buffer</code> objects will be passed to the callback instead.</p>\n<pre><code class=\"language-js\">const { exec } = require('child_process');\nexec('cat *.js missing_file | wc -l', (error, stdout, stderr) => {\n if (error) {\n console.error(`exec error: ${error}`);\n return;\n }\n console.log(`stdout: ${stdout}`);\n console.log(`stderr: ${stderr}`);\n});\n</code></pre>\n<p>If <code>timeout</code> is greater than <code>0</code>, the parent will send the signal\nidentified by the <code>killSignal</code> property (the default is <code>'SIGTERM'</code>) if the\nchild runs longer than <code>timeout</code> milliseconds.</p>\n<p>Unlike the <a href=\"http://man7.org/linux/man-pages/man3/exec.3.html\"><code>exec(3)</code></a> POSIX system call, <code>child_process.exec()</code> does not replace\nthe existing process and uses a shell to execute the command.</p>\n<p>If this method is invoked as its <a href=\"util.html#util_util_promisify_original\"><code>util.promisify()</code></a>ed version, it returns\na <code>Promise</code> for an <code>Object</code> with <code>stdout</code> and <code>stderr</code> properties. In case of an\nerror (including any error resulting in an exit code other than 0), a rejected\npromise is returned, with the same <code>error</code> object given in the callback, but\nwith an additional two properties <code>stdout</code> and <code>stderr</code>.</p>\n<pre><code class=\"language-js\">const util = require('util');\nconst exec = util.promisify(require('child_process').exec);\n\nasync function lsExample() {\n const { stdout, stderr } = await exec('ls');\n console.log('stdout:', stdout);\n console.log('stderr:', stderr);\n}\nlsExample();\n</code></pre>"
},
{
"textRaw": "child_process.execFile(file[, args][, options][, callback])",
"type": "method",
"name": "execFile",
"meta": {
"added": [
"v0.1.91"
],
"changes": [
{
"version": "v8.8.0",
"pr-url": "https://github.com/nodejs/node/pull/15380",
"description": "The `windowsHide` option is supported now."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {ChildProcess}",
"name": "return",
"type": "ChildProcess"
},
"params": [
{
"textRaw": "`file` {string} The name or path of the executable file to run.",
"name": "file",
"type": "string",
"desc": "The name or path of the executable file to run."
},
{
"textRaw": "`args` {string[]} List of string arguments.",
"name": "args",
"type": "string[]",
"desc": "List of string arguments.",
"optional": true
},
{
"textRaw": "`options` {Object}",
"name": "options",
"type": "Object",
"options": [
{
"textRaw": "`cwd` {string} Current working directory of the child process.",
"name": "cwd",
"type": "string",
"desc": "Current working directory of the child process."
},
{
"textRaw": "`env` {Object} Environment key-value pairs.",
"name": "env",
"type": "Object",
"desc": "Environment key-value pairs."
},
{
"textRaw": "`encoding` {string} **Default:** `'utf8'`",
"name": "encoding",
"type": "string",
"default": "`'utf8'`"
},
{
"textRaw": "`timeout` {number} **Default:** `0`",
"name": "timeout",
"type": "number",
"default": "`0`"
},
{
"textRaw": "`maxBuffer` {number} Largest amount of data in bytes allowed on stdout or stderr. If exceeded, the child process is terminated. See caveat at [`maxBuffer` and Unicode][]. **Default:** `200 * 1024`.",
"name": "maxBuffer",
"type": "number",
"default": "`200 * 1024`",
"desc": "Largest amount of data in bytes allowed on stdout or stderr. If exceeded, the child process is terminated. See caveat at [`maxBuffer` and Unicode][]."
},
{
"textRaw": "`killSignal` {string|integer} **Default:** `'SIGTERM'`",
"name": "killSignal",
"type": "string|integer",
"default": "`'SIGTERM'`"
},
{
"textRaw": "`uid` {number} Sets the user identity of the process (see setuid(2)).",
"name": "uid",
"type": "number",
"desc": "Sets the user identity of the process (see setuid(2))."
},
{
"textRaw": "`gid` {number} Sets the group identity of the process (see setgid(2)).",
"name": "gid",
"type": "number",
"desc": "Sets the group identity of the process (see setgid(2))."
},
{
"textRaw": "`windowsHide` {boolean} Hide the subprocess console window that would normally be created on Windows systems. **Default:** `false`.",
"name": "windowsHide",
"type": "boolean",
"default": "`false`",
"desc": "Hide the subprocess console window that would normally be created on Windows systems."
},
{
"textRaw": "`windowsVerbatimArguments` {boolean} No quoting or escaping of arguments is done on Windows. Ignored on Unix. **Default:** `false`.",
"name": "windowsVerbatimArguments",
"type": "boolean",
"default": "`false`",
"desc": "No quoting or escaping of arguments is done on Windows. Ignored on Unix."
},
{
"textRaw": "`shell` {boolean|string} If `true`, runs `command` inside of a shell. Uses `'/bin/sh'` on UNIX, and `process.env.ComSpec` on Windows. A different shell can be specified as a string. See [Shell Requirements][] and [Default Windows Shell][]. **Default:** `false` (no shell).",
"name": "shell",
"type": "boolean|string",
"default": "`false` (no shell)",
"desc": "If `true`, runs `command` inside of a shell. Uses `'/bin/sh'` on UNIX, and `process.env.ComSpec` on Windows. A different shell can be specified as a string. See [Shell Requirements][] and [Default Windows Shell][]."
}
],
"optional": true
},
{
"textRaw": "`callback` {Function} Called with the output when process terminates.",
"name": "callback",
"type": "Function",
"desc": "Called with the output when process terminates.",
"options": [
{
"textRaw": "`error` {Error}",
"name": "error",
"type": "Error"
},
{
"textRaw": "`stdout` {string|Buffer}",
"name": "stdout",
"type": "string|Buffer"
},
{
"textRaw": "`stderr` {string|Buffer}",
"name": "stderr",
"type": "string|Buffer"
}
],
"optional": true
}
]
}
],
"desc": "<p>The <code>child_process.execFile()</code> function is similar to <a href=\"#child_process_child_process_exec_command_options_callback\"><code>child_process.exec()</code></a>\nexcept that it does not spawn a shell by default. Rather, the specified executable <code>file</code>\nis spawned directly as a new process making it slightly more efficient than\n<a href=\"#child_process_child_process_exec_command_options_callback\"><code>child_process.exec()</code></a>.</p>\n<p>The same options as <a href=\"#child_process_child_process_exec_command_options_callback\"><code>child_process.exec()</code></a> are supported. Since a shell is not\nspawned, behaviors such as I/O redirection and file globbing are not supported.</p>\n<pre><code class=\"language-js\">const { execFile } = require('child_process');\nconst child = execFile('node', ['--version'], (error, stdout, stderr) => {\n if (error) {\n throw error;\n }\n console.log(stdout);\n});\n</code></pre>\n<p>The <code>stdout</code> and <code>stderr</code> arguments passed to the callback will contain the\nstdout and stderr output of the child process. By default, Node.js will decode\nthe output as UTF-8 and pass strings to the callback. The <code>encoding</code> option\ncan be used to specify the character encoding used to decode the stdout and\nstderr output. If <code>encoding</code> is <code>'buffer'</code>, or an unrecognized character\nencoding, <code>Buffer</code> objects will be passed to the callback instead.</p>\n<p>If this method is invoked as its <a href=\"util.html#util_util_promisify_original\"><code>util.promisify()</code></a>ed version, it returns\na <code>Promise</code> for an <code>Object</code> with <code>stdout</code> and <code>stderr</code> properties. In case of an\nerror (including any error resulting in an exit code other than 0), a rejected\npromise is returned, with the same <code>error</code> object given in the\ncallback, but with an additional two properties <code>stdout</code> and <code>stderr</code>.</p>\n<pre><code class=\"language-js\">const util = require('util');\nconst execFile = util.promisify(require('child_process').execFile);\nasync function getVersion() {\n const { stdout } = await execFile('node', ['--version']);\n console.log(stdout);\n}\ngetVersion();\n</code></pre>\n<p><strong>If the <code>shell</code> option is enabled, do not pass unsanitized user input to this\nfunction. Any input containing shell metacharacters may be used to trigger\narbitrary command execution.</strong></p>"
},
{
"textRaw": "child_process.fork(modulePath[, args][, options])",
"type": "method",
"name": "fork",
"meta": {
"added": [
"v0.5.0"
],
"changes": [
{
"version": "v8.0.0",
"pr-url": "https://github.com/nodejs/node/pull/10866",
"description": "The `stdio` option can now be a string."
},
{
"version": "v6.4.0",
"pr-url": "https://github.com/nodejs/node/pull/7811",
"description": "The `stdio` option is supported now."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {ChildProcess}",
"name": "return",
"type": "ChildProcess"
},
"params": [
{
"textRaw": "`modulePath` {string} The module to run in the child.",
"name": "modulePath",
"type": "string",
"desc": "The module to run in the child."
},
{
"textRaw": "`args` {string[]} List of string arguments.",
"name": "args",
"type": "string[]",
"desc": "List of string arguments.",
"optional": true
},
{
"textRaw": "`options` {Object}",
"name": "options",
"type": "Object",
"options": [
{
"textRaw": "`cwd` {string} Current working directory of the child process.",
"name": "cwd",
"type": "string",
"desc": "Current working directory of the child process."
},
{
"textRaw": "`env` {Object} Environment key-value pairs.",
"name": "env",
"type": "Object",
"desc": "Environment key-value pairs."
},
{
"textRaw": "`execPath` {string} Executable used to create the child process.",
"name": "execPath",
"type": "string",
"desc": "Executable used to create the child process."
},
{
"textRaw": "`execArgv` {string[]} List of string arguments passed to the executable. **Default:** `process.execArgv`.",
"name": "execArgv",
"type": "string[]",
"default": "`process.execArgv`",
"desc": "List of string arguments passed to the executable."
},
{
"textRaw": "`silent` {boolean} If `true`, stdin, stdout, and stderr of the child will be piped to the parent, otherwise they will be inherited from the parent, see the `'pipe'` and `'inherit'` options for [`child_process.spawn()`][]'s [`stdio`][] for more details. **Default:** `false`.",
"name": "silent",
"type": "boolean",
"default": "`false`",
"desc": "If `true`, stdin, stdout, and stderr of the child will be piped to the parent, otherwise they will be inherited from the parent, see the `'pipe'` and `'inherit'` options for [`child_process.spawn()`][]'s [`stdio`][] for more details."
},
{
"textRaw": "`stdio` {Array|string} See [`child_process.spawn()`][]'s [`stdio`][]. When this option is provided, it overrides `silent`. If the array variant is used, it must contain exactly one item with value `'ipc'` or an error will be thrown. For instance `[0, 1, 2, 'ipc']`.",
"name": "stdio",
"type": "Array|string",
"desc": "See [`child_process.spawn()`][]'s [`stdio`][]. When this option is provided, it overrides `silent`. If the array variant is used, it must contain exactly one item with value `'ipc'` or an error will be thrown. For instance `[0, 1, 2, 'ipc']`."
},
{
"textRaw": "`windowsVerbatimArguments` {boolean} No quoting or escaping of arguments is done on Windows. Ignored on Unix. **Default:** `false`.",
"name": "windowsVerbatimArguments",
"type": "boolean",
"default": "`false`",
"desc": "No quoting or escaping of arguments is done on Windows. Ignored on Unix."
},
{
"textRaw": "`uid` {number} Sets the user identity of the process (see setuid(2)).",
"name": "uid",
"type": "number",
"desc": "Sets the user identity of the process (see setuid(2))."
},
{
"textRaw": "`gid` {number} Sets the group identity of the process (see setgid(2)).",
"name": "gid",
"type": "number",
"desc": "Sets the group identity of the process (see setgid(2))."
}
],
"optional": true
}
]
}
],
"desc": "<p>The <code>child_process.fork()</code> method is a special case of\n<a href=\"#child_process_child_process_spawn_command_args_options\"><code>child_process.spawn()</code></a> used specifically to spawn new Node.js processes.\nLike <a href=\"#child_process_child_process_spawn_command_args_options\"><code>child_process.spawn()</code></a>, a <a href=\"#child_process_child_process\"><code>ChildProcess</code></a> object is returned. The returned\n<a href=\"#child_process_child_process\"><code>ChildProcess</code></a> will have an additional communication channel built-in that\nallows messages to be passed back and forth between the parent and child. See\n<a href=\"#child_process_subprocess_send_message_sendhandle_options_callback\"><code>subprocess.send()</code></a> for details.</p>\n<p>It is important to keep in mind that spawned Node.js child processes are\nindependent of the parent with exception of the IPC communication channel\nthat is established between the two. Each process has its own memory, with\ntheir own V8 instances. Because of the additional resource allocations\nrequired, spawning a large number of child Node.js processes is not\nrecommended.</p>\n<p>By default, <code>child_process.fork()</code> will spawn new Node.js instances using the\n<a href=\"process.html#process_process_execpath\"><code>process.execPath</code></a> of the parent process. The <code>execPath</code> property in the\n<code>options</code> object allows for an alternative execution path to be used.</p>\n<p>Node.js processes launched with a custom <code>execPath</code> will communicate with the\nparent process using the file descriptor (fd) identified using the\nenvironment variable <code>NODE_CHANNEL_FD</code> on the child process.</p>\n<p>Unlike the <a href=\"http://man7.org/linux/man-pages/man2/fork.2.html\"><code>fork(2)</code></a> POSIX system call, <code>child_process.fork()</code> does not clone the\ncurrent process.</p>\n<p>The <code>shell</code> option available in <a href=\"#child_process_child_process_spawn_command_args_options\"><code>child_process.spawn()</code></a> is not supported by\n<code>child_process.fork()</code> and will be ignored if set.</p>"
},
{
"textRaw": "child_process.spawn(command[, args][, options])",
"type": "method",
"name": "spawn",
"meta": {
"added": [
"v0.1.90"
],
"changes": [
{
"version": "v8.8.0",
"pr-url": "https://github.com/nodejs/node/pull/15380",
"description": "The `windowsHide` option is supported now."
},
{
"version": "v6.4.0",
"pr-url": "https://github.com/nodejs/node/pull/7696",
"description": "The `argv0` option is supported now."
},
{
"version": "v5.7.0",
"pr-url": "https://github.com/nodejs/node/pull/4598",
"description": "The `shell` option is supported now."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {ChildProcess}",
"name": "return",
"type": "ChildProcess"
},
"params": [
{
"textRaw": "`command` {string} The command to run.",
"name": "command",
"type": "string",
"desc": "The command to run."
},
{
"textRaw": "`args` {string[]} List of string arguments.",
"name": "args",
"type": "string[]",
"desc": "List of string arguments.",
"optional": true
},
{
"textRaw": "`options` {Object}",
"name": "options",
"type": "Object",
"options": [
{
"textRaw": "`cwd` {string} Current working directory of the child process.",
"name": "cwd",
"type": "string",
"desc": "Current working directory of the child process."
},
{
"textRaw": "`env` {Object} Environment key-value pairs.",
"name": "env",
"type": "Object",
"desc": "Environment key-value pairs."
},
{
"textRaw": "`argv0` {string} Explicitly set the value of `argv[0]` sent to the child process. This will be set to `command` if not specified.",
"name": "argv0",
"type": "string",
"desc": "Explicitly set the value of `argv[0]` sent to the child process. This will be set to `command` if not specified."
},
{
"textRaw": "`stdio` {Array|string} Child's stdio configuration (see [`options.stdio`][`stdio`]).",
"name": "stdio",
"type": "Array|string",
"desc": "Child's stdio configuration (see [`options.stdio`][`stdio`])."
},
{
"textRaw": "`detached` {boolean} Prepare child to run independently of its parent process. Specific behavior depends on the platform, see [`options.detached`][]).",
"name": "detached",
"type": "boolean",
"desc": "Prepare child to run independently of its parent process. Specific behavior depends on the platform, see [`options.detached`][])."
},
{
"textRaw": "`uid` {number} Sets the user identity of the process (see setuid(2)).",
"name": "uid",
"type": "number",
"desc": "Sets the user identity of the process (see setuid(2))."
},
{
"textRaw": "`gid` {number} Sets the group identity of the process (see setgid(2)).",
"name": "gid",
"type": "number",
"desc": "Sets the group identity of the process (see setgid(2))."
},
{
"textRaw": "`shell` {boolean|string} If `true`, runs `command` inside of a shell. Uses `'/bin/sh'` on UNIX, and `process.env.ComSpec` on Windows. A different shell can be specified as a string. See [Shell Requirements][] and [Default Windows Shell][]. **Default:** `false` (no shell).",
"name": "shell",
"type": "boolean|string",
"default": "`false` (no shell)",
"desc": "If `true`, runs `command` inside of a shell. Uses `'/bin/sh'` on UNIX, and `process.env.ComSpec` on Windows. A different shell can be specified as a string. See [Shell Requirements][] and [Default Windows Shell][]."
},
{
"textRaw": "`windowsVerbatimArguments` {boolean} No quoting or escaping of arguments is done on Windows. Ignored on Unix. This is set to `true` automatically when `shell` is specified and is CMD. **Default:** `false`.",
"name": "windowsVerbatimArguments",
"type": "boolean",
"default": "`false`",
"desc": "No quoting or escaping of arguments is done on Windows. Ignored on Unix. This is set to `true` automatically when `shell` is specified and is CMD."
},
{
"textRaw": "`windowsHide` {boolean} Hide the subprocess console window that would normally be created on Windows systems. **Default:** `false`.",
"name": "windowsHide",
"type": "boolean",
"default": "`false`",
"desc": "Hide the subprocess console window that would normally be created on Windows systems."
}
],
"optional": true
}
]
}
],
"desc": "<p>The <code>child_process.spawn()</code> method spawns a new process using the given\n<code>command</code>, with command line arguments in <code>args</code>. If omitted, <code>args</code> defaults\nto an empty array.</p>\n<p><strong>If the <code>shell</code> option is enabled, do not pass unsanitized user input to this\nfunction. Any input containing shell metacharacters may be used to trigger\narbitrary command execution.</strong></p>\n<p>A third argument may be used to specify additional options, with these defaults:</p>\n<pre><code class=\"language-js\">const defaults = {\n cwd: undefined,\n env: process.env\n};\n</code></pre>\n<p>Use <code>cwd</code> to specify the working directory from which the process is spawned.\nIf not given, the default is to inherit the current working directory.</p>\n<p>Use <code>env</code> to specify environment variables that will be visible to the new\nprocess, the default is <a href=\"process.html#process_process_env\"><code>process.env</code></a>.</p>\n<p><code>undefined</code> values in <code>env</code> will be ignored.</p>\n<p>Example of running <code>ls -lh /usr</code>, capturing <code>stdout</code>, <code>stderr</code>, and the\nexit code:</p>\n<pre><code class=\"language-js\">const { spawn } = require('child_process');\nconst ls = spawn('ls', ['-lh', '/usr']);\n\nls.stdout.on('data', (data) => {\n console.log(`stdout: ${data}`);\n});\n\nls.stderr.on('data', (data) => {\n console.log(`stderr: ${data}`);\n});\n\nls.on('close', (code) => {\n console.log(`child process exited with code ${code}`);\n});\n</code></pre>\n<p>Example: A very elaborate way to run <code>ps ax | grep ssh</code></p>\n<pre><code class=\"language-js\">const { spawn } = require('child_process');\nconst ps = spawn('ps', ['ax']);\nconst grep = spawn('grep', ['ssh']);\n\nps.stdout.on('data', (data) => {\n grep.stdin.write(data);\n});\n\nps.stderr.on('data', (data) => {\n console.log(`ps stderr: ${data}`);\n});\n\nps.on('close', (code) => {\n if (code !== 0) {\n console.log(`ps process exited with code ${code}`);\n }\n grep.stdin.end();\n});\n\ngrep.stdout.on('data', (data) => {\n console.log(data.toString());\n});\n\ngrep.stderr.on('data', (data) => {\n console.log(`grep stderr: ${data}`);\n});\n\ngrep.on('close', (code) => {\n if (code !== 0) {\n console.log(`grep process exited with code ${code}`);\n }\n});\n</code></pre>\n<p>Example of checking for failed <code>spawn</code>:</p>\n<pre><code class=\"language-js\">const { spawn } = require('child_process');\nconst subprocess = spawn('bad_command');\n\nsubprocess.on('error', (err) => {\n console.log('Failed to start subprocess.');\n});\n</code></pre>\n<p>Certain platforms (macOS, Linux) will use the value of <code>argv[0]</code> for the process\ntitle while others (Windows, SunOS) will use <code>command</code>.</p>\n<p>Node.js currently overwrites <code>argv[0]</code> with <code>process.execPath</code> on startup, so\n<code>process.argv[0]</code> in a Node.js child process will not match the <code>argv0</code>\nparameter passed to <code>spawn</code> from the parent, retrieve it with the\n<code>process.argv0</code> property instead.</p>",
"properties": [
{
"textRaw": "options.detached",
"name": "detached",
"meta": {
"added": [
"v0.7.10"
],
"changes": []
},
"desc": "<p>On Windows, setting <code>options.detached</code> to <code>true</code> makes it possible for the\nchild process to continue running after the parent exits. The child will have\nits own console window. <em>Once enabled for a child process, it cannot be\ndisabled</em>.</p>\n<p>On non-Windows platforms, if <code>options.detached</code> is set to <code>true</code>, the child\nprocess will be made the leader of a new process group and session. Note that\nchild processes may continue running after the parent exits regardless of\nwhether they are detached or not. See <a href=\"http://man7.org/linux/man-pages/man2/setsid.2.html\"><code>setsid(2)</code></a> for more information.</p>\n<p>By default, the parent will wait for the detached child to exit. To prevent the\nparent from waiting for a given <code>subprocess</code> to exit, use the\n<code>subprocess.unref()</code> method. Doing so will cause the parent's event loop to not\ninclude the child in its reference count, allowing the parent to exit\nindependently of the child, unless there is an established IPC channel between\nthe child and the parent.</p>\n<p>When using the <code>detached</code> option to start a long-running process, the process\nwill not stay running in the background after the parent exits unless it is\nprovided with a <code>stdio</code> configuration that is not connected to the parent.\nIf the parent's <code>stdio</code> is inherited, the child will remain attached to the\ncontrolling terminal.</p>\n<p>Example of a long-running process, by detaching and also ignoring its parent\n<code>stdio</code> file descriptors, in order to ignore the parent's termination:</p>\n<pre><code class=\"language-js\">const { spawn } = require('child_process');\n\nconst subprocess = spawn(process.argv[0], ['child_program.js'], {\n detached: true,\n stdio: 'ignore'\n});\n\nsubprocess.unref();\n</code></pre>\n<p>Alternatively one can redirect the child process' output into files:</p>\n<pre><code class=\"language-js\">const fs = require('fs');\nconst { spawn } = require('child_process');\nconst out = fs.openSync('./out.log', 'a');\nconst err = fs.openSync('./out.log', 'a');\n\nconst subprocess = spawn('prg', [], {\n detached: true,\n stdio: [ 'ignore', out, err ]\n});\n\nsubprocess.unref();\n</code></pre>"
},
{
"textRaw": "options.stdio",
"name": "stdio",
"meta": {
"added": [
"v0.7.10"
],
"changes": [
{
"version": "v3.3.1",
"pr-url": "https://github.com/nodejs/node/pull/2727",
"description": "The value `0` is now accepted as a file descriptor."
}
]
},
"desc": "<p>The <code>options.stdio</code> option is used to configure the pipes that are established\nbetween the parent and child process. By default, the child's stdin, stdout,\nand stderr are redirected to corresponding <a href=\"#child_process_subprocess_stdin\"><code>subprocess.stdin</code></a>,\n<a href=\"#child_process_subprocess_stdout\"><code>subprocess.stdout</code></a>, and <a href=\"#child_process_subprocess_stderr\"><code>subprocess.stderr</code></a> streams on the\n<a href=\"#child_process_child_process\"><code>ChildProcess</code></a> object. This is equivalent to setting the <code>options.stdio</code>\nequal to <code>['pipe', 'pipe', 'pipe']</code>.</p>\n<p>For convenience, <code>options.stdio</code> may be one of the following strings:</p>\n<ul>\n<li><code>'pipe'</code> - equivalent to <code>['pipe', 'pipe', 'pipe']</code> (the default)</li>\n<li><code>'ignore'</code> - equivalent to <code>['ignore', 'ignore', 'ignore']</code></li>\n<li><code>'inherit'</code> - equivalent to <code>['inherit', 'inherit', 'inherit']</code> or <code>[0, 1, 2]</code></li>\n</ul>\n<p>Otherwise, the value of <code>options.stdio</code> is an array where each index corresponds\nto an fd in the child. The fds 0, 1, and 2 correspond to stdin, stdout,\nand stderr, respectively. Additional fds can be specified to create additional\npipes between the parent and child. The value is one of the following:</p>\n<ol>\n<li>\n<p><code>'pipe'</code> - Create a pipe between the child process and the parent process.\nThe parent end of the pipe is exposed to the parent as a property on the\n<code>child_process</code> object as <a href=\"#child_process_options_stdio\"><code>subprocess.stdio[fd]</code></a>. Pipes created\nfor fds 0 - 2 are also available as <a href=\"#child_process_subprocess_stdin\"><code>subprocess.stdin</code></a>,\n<a href=\"#child_process_subprocess_stdout\"><code>subprocess.stdout</code></a> and <a href=\"#child_process_subprocess_stderr\"><code>subprocess.stderr</code></a>, respectively.</p>\n</li>\n<li>\n<p><code>'ipc'</code> - Create an IPC channel for passing messages/file descriptors\nbetween parent and child. A <a href=\"#child_process_child_process\"><code>ChildProcess</code></a> may have at most <em>one</em> IPC stdio\nfile descriptor. Setting this option enables the <a href=\"#child_process_subprocess_send_message_sendhandle_options_callback\"><code>subprocess.send()</code></a>\nmethod. If the child is a Node.js process, the presence of an IPC channel\nwill enable <a href=\"process.html#process_process_send_message_sendhandle_options_callback\"><code>process.send()</code></a> and <a href=\"process.html#process_process_disconnect\"><code>process.disconnect()</code></a> methods,\nas well as <a href=\"process.html#process_event_disconnect\"><code>'disconnect'</code></a> and <a href=\"process.html#process_event_message\"><code>'message'</code></a> events within the child.</p>\n<p>Accessing the IPC channel fd in any way other than <a href=\"process.html#process_process_send_message_sendhandle_options_callback\"><code>process.send()</code></a>\nor using the IPC channel with a child process that is not a Node.js instance\nis not supported.</p>\n</li>\n<li>\n<p><code>'ignore'</code> - Instructs Node.js to ignore the fd in the child. While Node.js\nwill always open fds 0 - 2 for the processes it spawns, setting the fd to\n<code>'ignore'</code> will cause Node.js to open <code>/dev/null</code> and attach it to the\nchild's fd.</p>\n</li>\n<li>\n<p><code>'inherit'</code> - Pass through the corresponding stdio stream to/from the\nparent process. In the first three positions, this is equivalent to\n<code>process.stdin</code>, <code>process.stdout</code>, and <code>process.stderr</code>, respectively. In\nany other position, equivalent to <code>'ignore'</code>.</p>\n</li>\n<li>\n<p><a href=\"stream.html#stream_stream\" class=\"type\"><Stream></a> object - Share a readable or writable stream that refers to a tty,\nfile, socket, or a pipe with the child process. The stream's underlying\nfile descriptor is duplicated in the child process to the fd that\ncorresponds to the index in the <code>stdio</code> array. Note that the stream must\nhave an underlying descriptor (file streams do not until the <code>'open'</code>\nevent has occurred).</p>\n</li>\n<li>\n<p>Positive integer - The integer value is interpreted as a file descriptor\nthat is currently open in the parent process. It is shared with the child\nprocess, similar to how <a href=\"stream.html#stream_stream\" class=\"type\"><Stream></a> objects can be shared.</p>\n</li>\n<li>\n<p><code>null</code>, <code>undefined</code> - Use default value. For stdio fds 0, 1, and 2 (in other\nwords, stdin, stdout, and stderr) a pipe is created. For fd 3 and up, the\ndefault is <code>'ignore'</code>.</p>\n</li>\n</ol>\n<pre><code class=\"language-js\">const { spawn } = require('child_process');\n\n// Child will use parent's stdios\nspawn('prg', [], { stdio: 'inherit' });\n\n// Spawn child sharing only stderr\nspawn('prg', [], { stdio: ['pipe', 'pipe', process.stderr] });\n\n// Open an extra fd=4, to interact with programs presenting a\n// startd-style interface.\nspawn('prg', [], { stdio: ['pipe', null, null, null, 'pipe'] });\n</code></pre>\n<p><em>It is worth noting that when an IPC channel is established between the\nparent and child processes, and the child is a Node.js process, the child\nis launched with the IPC channel unreferenced (using <code>unref()</code>) until the\nchild registers an event handler for the <a href=\"process.html#process_event_disconnect\"><code>'disconnect'</code></a> event\nor the <a href=\"process.html#process_event_message\"><code>'message'</code></a> event. This allows the child to exit\nnormally without the process being held open by the open IPC channel.</em></p>\n<p>On UNIX-like operating systems, the <a href=\"#child_process_child_process_spawn_command_args_options\"><code>child_process.spawn()</code></a> method\nperforms memory operations synchronously before decoupling the event loop\nfrom the child. Applications with a large memory footprint may find frequent\n<a href=\"#child_process_child_process_spawn_command_args_options\"><code>child_process.spawn()</code></a> calls to be a bottleneck. For more information,\nsee <a href=\"https://bugs.chromium.org/p/v8/issues/detail?id=7381\">V8 issue 7381</a>.</p>\n<p>See also: <a href=\"#child_process_child_process_exec_command_options_callback\"><code>child_process.exec()</code></a> and <a href=\"#child_process_child_process_fork_modulepath_args_options\"><code>child_process.fork()</code></a>.</p>"
}
]
}
],
"type": "module",
"displayName": "Asynchronous Process Creation"
},
{
"textRaw": "Synchronous Process Creation",
"name": "synchronous_process_creation",
"desc": "<p>The <a href=\"#child_process_child_process_spawnsync_command_args_options\"><code>child_process.spawnSync()</code></a>, <a href=\"#child_process_child_process_execsync_command_options\"><code>child_process.execSync()</code></a>, and\n<a href=\"#child_process_child_process_execfilesync_file_args_options\"><code>child_process.execFileSync()</code></a> methods are <strong>synchronous</strong> and <strong>WILL</strong> block\nthe Node.js event loop, pausing execution of any additional code until the\nspawned process exits.</p>\n<p>Blocking calls like these are mostly useful for simplifying general-purpose\nscripting tasks and for simplifying the loading/processing of application\nconfiguration at startup.</p>",
"methods": [
{
"textRaw": "child_process.execFileSync(file[, args][, options])",
"type": "method",
"name": "execFileSync",
"meta": {
"added": [
"v0.11.12"
],
"changes": [
{
"version": "v10.10.0",
"pr-url": "https://github.com/nodejs/node/pull/22409",
"description": "The `input` option can now be any `TypedArray` or a `DataView`."
},
{
"version": "v8.8.0",
"pr-url": "https://github.com/nodejs/node/pull/15380",
"description": "The `windowsHide` option is supported now."
},
{
"version": "v8.0.0",
"pr-url": "https://github.com/nodejs/node/pull/10653",
"description": "The `input` option can now be a `Uint8Array`."
},
{
"version": "v6.2.1, v4.5.0",
"pr-url": "https://github.com/nodejs/node/pull/6939",
"description": "The `encoding` option can now explicitly be set to `buffer`."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {Buffer|string} The stdout from the command.",
"name": "return",
"type": "Buffer|string",
"desc": "The stdout from the command."
},
"params": [
{
"textRaw": "`file` {string} The name or path of the executable file to run.",
"name": "file",
"type": "string",
"desc": "The name or path of the executable file to run."
},
{
"textRaw": "`args` {string[]} List of string arguments.",
"name": "args",
"type": "string[]",
"desc": "List of string arguments.",
"optional": true
},
{
"textRaw": "`options` {Object}",
"name": "options",
"type": "Object",
"options": [
{
"textRaw": "`cwd` {string} Current working directory of the child process.",
"name": "cwd",
"type": "string",
"desc": "Current working directory of the child process."
},
{
"textRaw": "`input` {string|Buffer|TypedArray|DataView} The value which will be passed as stdin to the spawned process. Supplying this value will override `stdio[0]`.",
"name": "input",
"type": "string|Buffer|TypedArray|DataView",
"desc": "The value which will be passed as stdin to the spawned process. Supplying this value will override `stdio[0]`."
},
{
"textRaw": "`stdio` {string|Array} Child's stdio configuration. `stderr` by default will be output to the parent process' stderr unless `stdio` is specified. **Default:** `'pipe'`.",
"name": "stdio",
"type": "string|Array",
"default": "`'pipe'`",
"desc": "Child's stdio configuration. `stderr` by default will be output to the parent process' stderr unless `stdio` is specified."
},
{
"textRaw": "`env` {Object} Environment key-value pairs.",
"name": "env",
"type": "Object",
"desc": "Environment key-value pairs."
},
{
"textRaw": "`uid` {number} Sets the user identity of the process (see setuid(2)).",
"name": "uid",
"type": "number",
"desc": "Sets the user identity of the process (see setuid(2))."
},
{
"textRaw": "`gid` {number} Sets the group identity of the process (see setgid(2)).",
"name": "gid",
"type": "number",
"desc": "Sets the group identity of the process (see setgid(2))."
},
{
"textRaw": "`timeout` {number} In milliseconds the maximum amount of time the process is allowed to run. **Default:** `undefined`.",
"name": "timeout",
"type": "number",
"default": "`undefined`",
"desc": "In milliseconds the maximum amount of time the process is allowed to run."
},
{
"textRaw": "`killSignal` {string|integer} The signal value to be used when the spawned process will be killed. **Default:** `'SIGTERM'`.",
"name": "killSignal",
"type": "string|integer",
"default": "`'SIGTERM'`",
"desc": "The signal value to be used when the spawned process will be killed."
},
{
"textRaw": "`maxBuffer` {number} Largest amount of data in bytes allowed on stdout or stderr. If exceeded, the child process is terminated. See caveat at [`maxBuffer` and Unicode][]. **Default:** `200 * 1024`.",
"name": "maxBuffer",
"type": "number",
"default": "`200 * 1024`",
"desc": "Largest amount of data in bytes allowed on stdout or stderr. If exceeded, the child process is terminated. See caveat at [`maxBuffer` and Unicode][]."
},
{
"textRaw": "`encoding` {string} The encoding used for all stdio inputs and outputs. **Default:** `'buffer'`.",
"name": "encoding",
"type": "string",
"default": "`'buffer'`",
"desc": "The encoding used for all stdio inputs and outputs."
},
{
"textRaw": "`windowsHide` {boolean} Hide the subprocess console window that would normally be created on Windows systems. **Default:** `false`.",
"name": "windowsHide",
"type": "boolean",
"default": "`false`",
"desc": "Hide the subprocess console window that would normally be created on Windows systems."
},
{
"textRaw": "`shell` {boolean|string} If `true`, runs `command` inside of a shell. Uses `'/bin/sh'` on UNIX, and `process.env.ComSpec` on Windows. A different shell can be specified as a string. See [Shell Requirements][] and [Default Windows Shell][]. **Default:** `false` (no shell).",
"name": "shell",
"type": "boolean|string",
"default": "`false` (no shell)",
"desc": "If `true`, runs `command` inside of a shell. Uses `'/bin/sh'` on UNIX, and `process.env.ComSpec` on Windows. A different shell can be specified as a string. See [Shell Requirements][] and [Default Windows Shell][]."
}
],
"optional": true
}
]
}
],
"desc": "<p>The <code>child_process.execFileSync()</code> method is generally identical to\n<a href=\"#child_process_child_process_execfile_file_args_options_callback\"><code>child_process.execFile()</code></a> with the exception that the method will not return\nuntil the child process has fully closed. When a timeout has been encountered\nand <code>killSignal</code> is sent, the method won't return until the process has\ncompletely exited.</p>\n<p>If the child process intercepts and handles the <code>SIGTERM</code> signal and\ndoes not exit, the parent process will still wait until the child process has\nexited.</p>\n<p>If the process times out or has a non-zero exit code, this method <strong><em>will</em></strong>\nthrow an <a href=\"errors.html#errors_class_error\"><code>Error</code></a> that will include the full result of the underlying\n<a href=\"#child_process_child_process_spawnsync_command_args_options\"><code>child_process.spawnSync()</code></a>.</p>\n<p><strong>If the <code>shell</code> option is enabled, do not pass unsanitized user input to this\nfunction. Any input containing shell metacharacters may be used to trigger\narbitrary command execution.</strong></p>"
},
{
"textRaw": "child_process.execSync(command[, options])",
"type": "method",
"name": "execSync",
"meta": {
"added": [
"v0.11.12"
],
"changes": [
{
"version": "v10.10.0",
"pr-url": "https://github.com/nodejs/node/pull/22409",
"description": "The `input` option can now be any `TypedArray` or a `DataView`."
},
{
"version": "v8.8.0",
"pr-url": "https://github.com/nodejs/node/pull/15380",
"description": "The `windowsHide` option is supported now."
},
{
"version": "v8.0.0",
"pr-url": "https://github.com/nodejs/node/pull/10653",
"description": "The `input` option can now be a `Uint8Array`."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {Buffer|string} The stdout from the command.",
"name": "return",
"type": "Buffer|string",
"desc": "The stdout from the command."
},
"params": [
{
"textRaw": "`command` {string} The command to run.",
"name": "command",
"type": "string",
"desc": "The command to run."
},
{
"textRaw": "`options` {Object}",
"name": "options",
"type": "Object",
"options": [
{
"textRaw": "`cwd` {string} Current working directory of the child process.",
"name": "cwd",
"type": "string",
"desc": "Current working directory of the child process."
},
{
"textRaw": "`input` {string|Buffer|TypedArray|DataView} The value which will be passed as stdin to the spawned process. Supplying this value will override `stdio[0]`.",
"name": "input",
"type": "string|Buffer|TypedArray|DataView",
"desc": "The value which will be passed as stdin to the spawned process. Supplying this value will override `stdio[0]`."
},
{
"textRaw": "`stdio` {string|Array} Child's stdio configuration. `stderr` by default will be output to the parent process' stderr unless `stdio` is specified. **Default:** `'pipe'`.",
"name": "stdio",
"type": "string|Array",
"default": "`'pipe'`",
"desc": "Child's stdio configuration. `stderr` by default will be output to the parent process' stderr unless `stdio` is specified."
},
{
"textRaw": "`env` {Object} Environment key-value pairs.",
"name": "env",
"type": "Object",
"desc": "Environment key-value pairs."
},
{
"textRaw": "`shell` {string} Shell to execute the command with. See [Shell Requirements][] and [Default Windows Shell][]. **Default:** `'/bin/sh'` on UNIX, `process.env.ComSpec` on Windows.",
"name": "shell",
"type": "string",
"default": "`'/bin/sh'` on UNIX, `process.env.ComSpec` on Windows",
"desc": "Shell to execute the command with. See [Shell Requirements][] and [Default Windows Shell][]."
},
{
"textRaw": "`uid` {number} Sets the user identity of the process. (See setuid(2)).",
"name": "uid",
"type": "number",
"desc": "Sets the user identity of the process. (See setuid(2))."
},
{
"textRaw": "`gid` {number} Sets the group identity of the process. (See setgid(2)).",
"name": "gid",
"type": "number",
"desc": "Sets the group identity of the process. (See setgid(2))."
},
{
"textRaw": "`timeout` {number} In milliseconds the maximum amount of time the process is allowed to run. **Default:** `undefined`.",
"name": "timeout",
"type": "number",
"default": "`undefined`",
"desc": "In milliseconds the maximum amount of time the process is allowed to run."
},
{
"textRaw": "`killSignal` {string|integer} The signal value to be used when the spawned process will be killed. **Default:** `'SIGTERM'`.",
"name": "killSignal",
"type": "string|integer",
"default": "`'SIGTERM'`",
"desc": "The signal value to be used when the spawned process will be killed."
},
{
"textRaw": "`maxBuffer` {number} Largest amount of data in bytes allowed on stdout or stderr. If exceeded, the child process is terminated. See caveat at [`maxBuffer` and Unicode][]. **Default:** `200 * 1024`.",
"name": "maxBuffer",
"type": "number",
"default": "`200 * 1024`",
"desc": "Largest amount of data in bytes allowed on stdout or stderr. If exceeded, the child process is terminated. See caveat at [`maxBuffer` and Unicode][]."
},
{
"textRaw": "`encoding` {string} The encoding used for all stdio inputs and outputs. **Default:** `'buffer'`.",
"name": "encoding",
"type": "string",
"default": "`'buffer'`",
"desc": "The encoding used for all stdio inputs and outputs."
},
{
"textRaw": "`windowsHide` {boolean} Hide the subprocess console window that would normally be created on Windows systems. **Default:** `false`.",
"name": "windowsHide",
"type": "boolean",
"default": "`false`",
"desc": "Hide the subprocess console window that would normally be created on Windows systems."
}
],
"optional": true
}
]
}
],
"desc": "<p>The <code>child_process.execSync()</code> method is generally identical to\n<a href=\"#child_process_child_process_exec_command_options_callback\"><code>child_process.exec()</code></a> with the exception that the method will not return until\nthe child process has fully closed. When a timeout has been encountered and\n<code>killSignal</code> is sent, the method won't return until the process has completely\nexited. <em>Note that if the child process intercepts and handles the <code>SIGTERM</code>\nsignal and doesn't exit, the parent process will wait until the child\nprocess has exited.</em></p>\n<p>If the process times out or has a non-zero exit code, this method <strong><em>will</em></strong>\nthrow. The <a href=\"errors.html#errors_class_error\"><code>Error</code></a> object will contain the entire result from\n<a href=\"#child_process_child_process_spawnsync_command_args_options\"><code>child_process.spawnSync()</code></a>.</p>\n<p><strong>Never pass unsanitized user input to this function. Any input containing shell\nmetacharacters may be used to trigger arbitrary command execution.</strong></p>"
},
{
"textRaw": "child_process.spawnSync(command[, args][, options])",
"type": "method",
"name": "spawnSync",
"meta": {
"added": [
"v0.11.12"
],
"changes": [
{
"version": "v10.10.0",
"pr-url": "https://github.com/nodejs/node/pull/22409",
"description": "The `input` option can now be any `TypedArray` or a `DataView`."
},
{
"version": "v8.8.0",
"pr-url": "https://github.com/nodejs/node/pull/15380",
"description": "The `windowsHide` option is supported now."
},
{
"version": "v8.0.0",
"pr-url": "https://github.com/nodejs/node/pull/10653",
"description": "The `input` option can now be a `Uint8Array`."
},
{
"version": "v6.2.1, v4.5.0",
"pr-url": "https://github.com/nodejs/node/pull/6939",
"description": "The `encoding` option can now explicitly be set to `buffer`."
},
{
"version": "v5.7.0",
"pr-url": "https://github.com/nodejs/node/pull/4598",
"description": "The `shell` option is supported now."
}
]
},
"signatures": [
{
"return": {
"textRaw": "Returns: {Object}",
"name": "return",
"type": "Object",
"options": [
{
"textRaw": "`pid` {number} Pid of the child process.",
"name": "pid",
"type": "number",
"desc": "Pid of the child process."
},
{
"textRaw": "`output` {Array} Array of results from stdio output.",
"name": "output",
"type": "Array",
"desc": "Array of results from stdio output."
},
{
"textRaw": "`stdout` {Buffer|string} The contents of `output[1]`.",
"name": "stdout",
"type": "Buffer|string",
"desc": "The contents of `output[1]`."
},
{
"textRaw": "`stderr` {Buffer|string} The contents of `output[2]`.",
"name": "stderr",
"type": "Buffer|string",
"desc": "The contents of `output[2]`."
},
{
"textRaw": "`status` {number} The exit code of the child process.",
"name": "status",
"type": "number",
"desc": "The exit code of the child process."
},
{
"textRaw": "`signal` {string} The signal used to kill the child process.",
"name": "signal",
"type": "string",
"desc": "The signal used to kill the child process."
},
{
"textRaw": "`error` {Error} The error object if the child process failed or timed out.",
"name": "error",
"type": "Error",
"desc": "The error object if the child process failed or timed out."
}
]
},
"params": [
{
"textRaw": "`command` {string} The command to run.",
"name": "command",
"type": "string",
"desc": "The command to run."
},
{
"textRaw": "`args` {string[]} List of string arguments.",
"name": "args",
"type": "string[]",
"desc": "List of string arguments.",
"optional": true
},
{
"textRaw": "`options` {Object}",
"name": "options",
"type": "Object",
"options": [
{
"textRaw": "`cwd` {string} Current working directory of the child process.",
"name": "cwd",
"type": "string",
"desc": "Current working directory of the child process."
},
{
"textRaw": "`input` {string|Buffer|TypedArray|DataView} The value which will be passed as stdin to the spawned process. Supplying this value will override `stdio[0]`.",
"name": "input",
"type": "string|Buffer|TypedArray|DataView",
"desc": "The value which will be passed as stdin to the spawned process. Supplying this value will override `stdio[0]`."
},
{
"textRaw": "`argv0` {string} Explicitly set the value of `argv[0]` sent to the child process. This will be set to `command` if not specified.",
"name": "argv0",
"type": "string",
"desc": "Explicitly set the value of `argv[0]` sent to the child process. This will be set to `command` if not specified."
},
{
"textRaw": "`stdio` {string|Array} Child's stdio configuration.",
"name": "stdio",
"type": "string|Array",
"desc": "Child's stdio configuration."
},
{
"textRaw": "`env` {Object} Environment key-value pairs.",
"name": "env",
"type": "Object",
"desc": "Environment key-value pairs."
},
{
"textRaw": "`uid` {number} Sets the user identity of the process (see setuid(2)).",
"name": "uid",
"type": "number",
"desc": "Sets the user identity of the process (see setuid(2))."
},
{
"textRaw": "`gid` {number} Sets the group identity of the process (see setgid(2)).",
"name": "gid",
"type": "number",
"desc": "Sets the group identity of the process (see setgid(2))."
},