Questions tagged [child-process]

For questions regarding child-process

In Unix, a child process is typically created as a copy of the parent, using the fork system call. The child process can then overlay itself with a different program (using exec) as required.

Each process may create many child processes but will have at most one parent process; if a process does not have a parent this usually indicates that it was created directly by the kernel.

The inter communication between a child process and a parent process can be done through normal communication schemes such as pipes, sockets, message queues, shared memories.

When a child process terminates, some information is returned to the parent process. When a child process terminates before the parent has called wait, the kernel retains some information about the process, such as its exit status, to enable its parent to call wait later

2233 questions
11
votes
1 answer

How do I kill forked child process after use?

I have this function and fork a child process to run a heavy work on background. The work module sends message after it completes the work. How do I kill or close the forked process? function doWork() { var child = cp.fork(__dirname +…
codereviewanskquestions
  • 13,460
  • 29
  • 98
  • 167
11
votes
1 answer

Saving the output of a child process in a variable in the parent in NodeJS

I would like to start a child process in NodeJS and save it's output into a variable. The following code gives it to stdout: require("child_process").execSync("echo Hello World", {"stdio": "inherit"}); I have something in mind that is similar to…
pfo
  • 125
  • 1
  • 1
  • 5
11
votes
2 answers

Using two commands (using pipe |) with spawn

I'm converting a doc to a pdf (unoconv) in memory and printing (pdftotext) in the terminal with: unoconv -f pdf --stdout sample.doc | pdftotext -layout -enc UTF-8 - out.txt Is working. Now i want use this command with child_process.spawn: let…
user5526811
11
votes
2 answers

Node child process event listen

I use the node child_process API https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options var child = child_process.spawn(cmd, val, options); from the child I use the following…
07_05_GuyT
  • 2,787
  • 14
  • 43
  • 88
11
votes
3 answers

Setting Jekyll environment for GitHub Pages

I am building a site with Jekyll that I am hosting on GitHub Pages. I would like to be able to set the JEKYLL_ENV to 'production' (JEKYLL_ENV=production) when I deploy to GitHub Pages so I can do something like this: {% if jekyll.environment ==…
user2909019
  • 833
  • 1
  • 10
  • 19
11
votes
3 answers

Piping data from child to parent in nodejs

I have a nodejs parent process that starts up another nodejs child process. The child process executes some logic and then returns output to the parent. The output is large and I'm trying to use pipes to communicate, as suggested in documentation…
Tomasz Rakowski
  • 1,052
  • 4
  • 13
  • 27
11
votes
1 answer

How to pass function/callback to child process in Node.js?

Let's say I have a parent.js containing a method named parent var childProcess = require('child_process'); var options = { someData: {a:1, b:2, c:3}, asyncFn: function (data, callback) { /*do other async stuff here*/ } }; function…
kit
  • 305
  • 3
  • 13
11
votes
1 answer

child_process spawn in node.js security / escaping

In Node, I'm using a module (GM) and noticed that it uses spawn from the child_process module to pass arguments to GraphicMagick's convert executable. I'm passing user-submitted information to GM. Is there a security concern that the user could do…
stockholmux
  • 1,169
  • 11
  • 24
11
votes
3 answers

NodeJS - how to get spawned child to communicate with parent?

I'm trying this out: var child = spawn('node', args, {cwd: parentDir, stdio: 'ipc'} ); (args is an array of parameters) but it gives the following error: TypeError: Incorrect value of stdio option: ipc This actually works, so the problem seems…
rockamic
  • 151
  • 1
  • 2
  • 11
11
votes
2 answers

Is the try-catch-finally block synchronous in node.js?

I have some code runing in a child process in a node program like so: try{ var data = fs.readFileSync(urlPath, {"encoding":"utf8"}); } catch (err) { console.log("Error reading url file..."); throw err; } finally { console.log("File…
krb686
  • 1,726
  • 9
  • 26
  • 46
10
votes
3 answers

How can I make Perl wait for child processes started in the background with system()?

I have some Perl code that executes a shell script for multiple parameters, to simplify, I'll just assume that I have code that looks like this: for $p (@a){ system("/path/to/file.sh $p&"); } I'd like to do some more things after that, but I…
Osama Al-Maadeed
  • 5,654
  • 5
  • 28
  • 48
10
votes
2 answers

Pass function and arguments from node to python, using child_process

I am new to child_process and I want to experiment with its capabilities. Is there any way to pass a function and arguments to a python file, using spawn (or exec or execFile is spawn cannot do it)? I want to do something like…
codebot
  • 517
  • 8
  • 29
  • 55
10
votes
2 answers

child_process.execFile slow to exit

I have a Node script that calls an external program (PluginManager.exe) this way: const util = require('util'); const execFile = util.promisify(require('child_process').execFile); const process = execFile('PluginManager.exe',…
Sylvain
  • 19,099
  • 23
  • 96
  • 145
10
votes
1 answer

Buffer returned by child_process.execSync is incomplete

I have the following script which executes a shell command: #!/usr/bin/env node const { execSync } = require('child_process'); try { const data = execSync( 'yarn licenses generate-disclaimer --prod', { encoding: 'utf8',…
Andrii Chernenko
  • 9,873
  • 7
  • 71
  • 89
10
votes
1 answer

uglify crashing after running child_process.execFile

EDIT 2 I "solved" the problem, but I don't want to post it as an answer b/c it doesn't explain what actually happened. In the code for the .NET resourceReader.exe I use Console.OutputEncoding = System.Text.Encoding.UTF8; to output the…
just.another.programmer
  • 8,579
  • 8
  • 51
  • 90