Questions tagged [child-process]

For questions regarding child-process

1
vote
0answers
16 views

How to start electron application programically via child_process?

I need to start the electron.js application programically. Below solution with execa library works, however I did not find the answer, how to make console to display console.log() inside ...
1
vote
1answer
12 views

How to kill spawnSync after a timeout

I want to kill the spawnSync process in ES6 async / await. (async () => { const type = 'python'; const exefile = './test.py'; let opt = [file]; let result = await spawnSync(type,...
0
votes
0answers
14 views

Store stdout as variable and send it back to angular

I am working with angular and node, i want to call a cli command on button click on client side. The command line will call a python script I saw that i could do it with child process, by calling and ...
1
vote
0answers
25 views

How to get console.log() output from the child process in “execa”?

Below code starts Electron application, however, console.log() from the main process will not be available. import executeExternalCommand, { ExecaReturnValue } from 'execa'; async ...
0
votes
1answer
20 views

Can I use the child_process to spawn multiple python outputs on a server?

I am trying to use NodeJS to execute multiple python scripts and send the contents of those scripts to a local host. I would like to not be specific to the exact python script, but to use something ...
0
votes
1answer
22 views

python not working correctly when called from nodejs app with child-process

Im trying to run a python script that used deep learning model to classify an image wether it is NSFW or not, i use this script from here https://github.com/yahoo/open_nsfw and a custom model. The ...
0
votes
1answer
18 views

Node APP running under PM2 unable to run child process

I have a NodeJS app that is running under PM2 to keep the process running. The node app has a function to run a child process to execute a command to run some image processing. Everything worked ...
0
votes
1answer
11 views

What encoding does nodejs use for arguments in child_process.spawn and child_process.execFile?

In NodeJS, child_process.execFile and .spawn take this parameter: args <string[]> List of string arguments. How does NodeJS encode the strings you pass in this array? Context: I'm writing a ...
2
votes
2answers
69 views

How to wait for grandchild process (`bash` retval becomes -1 in Perl due to SIG CHLD)

I have a Perl script (snippet below) that runs in cron to perform system checks. I fork a child as a timeout and reap it with SIG{CHLD}. Perl does several system calls of Bash scripts and checks their ...
0
votes
1answer
17 views

Read everything from child_process.spawn's stderr in nodejs

Trying to run fping from nodejs via child_process.spawn() is and capturing output via cp.stderr.on('data') sometimes results in incomplete data in the buffer. Here's my sample snippet: const ...
1
vote
1answer
25 views

How to kill child process/close Chrome?

Let's start with the code: #!/usr/bin/env node const ChildProc = require('child_process'); const chrome = ChildProc.spawn('/usr/bin/google-chrome',['--incognito',`--app=data:text/html,<p>Hello ...
0
votes
1answer
31 views

How to kill a child process and allow parent process to continue

I am using node.js to monitor a website's API for commands and choose the appropriate child process based on the said command. Only one child process should be running at a time. As of now, child ...
-1
votes
1answer
22 views

how to run pm2 in spawn process remotely from another server, not a shell script problem

this is not a problem related to shell script , this a problem on how to restart or use pm2 commands from spawn process in nodejs from a remote server. running the pm2 commands solo or in a shell ...
2
votes
0answers
37 views

How do I convert an h.264 stream to MP4 using ffmpeg and pipe the result to the client?

I have an h.264 encoded stream of video on my server (node.js) and I want to use ffmpeg to convert it to an MP4 stream. Then I want to pipe that MP4 stream from the child process to the client using ...
3
votes
0answers
51 views

Race condition reading stdout and stderr of child process

In Go, I'm trying to: start a subprocess read from stdout and stderr separately implement an overall timeout After much googling, we've come up with some code that seems to do the job, most of the ...
1
vote
1answer
63 views

Check if a particular NPM package is installed globally

I'm trying to check if a particular npm package is installed/available globally using Nodejs. I managed to list the global dependencies/packages through the npm command npm list -g --depth=0. So i ...
1
vote
1answer
46 views

Threads running inside a child process are not timing out as per the set alarm time

This question is an extension to my previous question. The only addition here is that now I would like the threads to timeout if the operation is not complete within the set timeout duration. So ...
0
votes
0answers
15 views

Open explorer without opening duplicates from Node

I want to open the path of my build folder whenever I rebuild my application, which I am currently doing using require("child_process").exec("explorer build");. But if I forget to close the explorers ...
0
votes
0answers
44 views

How to fix Error: spawn npm ENOENT in windows 10?

I'm trying to create a CLI that automatically clones the vuex-store-starter template that I created. At the time of installation, it shows an error based on Error: spawn npm ENOENT Any help will be ...
0
votes
0answers
12 views

How to create a file with python scrip in nodejs child process?

I'm using a python 2.7 script to create a file, which I want to open later from a node.js server. When I run the script from cmd it creates a file, but when the node.js server runs the python script ...
0
votes
0answers
20 views

With construct in async await child process in node?

I'd like to start an external resource, and ping it until it is ready, then begin running some other function. I view this as sort of a with construct in other languages, where I'd say something like:...
0
votes
2answers
36 views

Nodejs: how to check if spawn is successfull?

I am spawing a command from my express script, but I need to distinguish between error and success. I was looking for a child.on('success'...) function, but it doesn't exist. This piece of code (of ...
0
votes
1answer
28 views

Is there synchronous version of child_process.fork() in node.js?

There is spawn and spawnSync, but there is no forkSync for fork. Or did I failed to find it? If not, why is it so that there is no forkSync?
1
vote
0answers
16 views

Run multiple times the same command in child_process in parallel

i'm currently facing a child_process problem which i can't find a way out. I would like to run a simple command on the server using child_process.spawn() ou child_process.exec() : let child = spawn('...
0
votes
1answer
16 views

When creating new process using exec() in nodejs, does it run in parallel with current process, how nodejs handles it?

Since nodejs is single threaded language, how does it creates new processes and handles it. const exec = require('child_process').exec; exec('my.bat', (err, stdout, stderr) => { if (err) { ...
0
votes
2answers
22 views

Understanding child_process module and exec functionality when using it to execute a file

I new to node.js and trying to understand the syntax and exactly what is happening line by line in my code. This code runs a file hello.js with one argument arg1 and takes some time to execute. The ...
0
votes
0answers
16 views

Catch EADDRINUSE from ChildProcess

I have a spawn process running the http-server. This is my simplified code: const params = ['node_modules/http-server/bin/http-server', '--cors', '-p']; const proc = cp.spawn('node', params, { stdio: ...
0
votes
2answers
49 views

Is it possible to comunicate between a nodejs process and a Electron child process?

I have an Electron app that is launched inside of my main nodejs application. The user has to launch my index.js and then, an Electron window spawn. The problem is that I can't comunicate between ...
0
votes
0answers
9 views

pg client connect causes child_process.execFile to hang

child_process.execFile seems to hang when pg.Client() connection is open. I was able to narrow it down to that for as soon as I comment out the pg.Client().connect() code, the execFile child process ...
1
vote
0answers
21 views

Pass app object from Parent to Node child process

I am working on creating a child process. As a part of that I need to pass the app object from parent to child process. parent.js module.exports = function (app) { // app object is available here. ...
0
votes
1answer
26 views

Node Child process is running continuously without closing after getting the data

I am working on a loopback project where I need to run a background job. Spawn node child process. Since I am beginner, documentation is little confusing. https://nodejs.org/api/child_process.html#...
0
votes
1answer
10 views

exec command doesn't work with variables added, but works without variables variables added

I'm trying to execute python file made by CaryKH called jumpcutter.py using child process This is a working function, where the exec command does work: function executePython(){ const { exec } = ...
9
votes
7answers
275 views

Script output is buffered into one message, despite separate echo statements?

I have a shell script with three echo statements: echo 'first message' echo 'second message' echo 'third message' I then run this script in node and collect the output via this code: var child ...
0
votes
2answers
39 views

Node JS - Cannot Kill Process Executed with Child Process Exec

We are trying to kill the process of a chrome browser launched with nodes child_process exec command var process = cp.exec(`"chrome.exe" --app="..."`, () => {}); // working great But when we try ...
0
votes
1answer
25 views

Spawn process that keeps running after app.quit()

How can I launch a user-defined application from an electron application. After the application is launched the electron application should quit, and restart after the program has finished. This to ...
0
votes
0answers
20 views

Issue with child_process spawnSync stdio when using ssh

I'm trying to start an interactive SSH session in a shell using spawnSync. const { spawnSync } = require('child_process') spawnSync('ssh', ['[email protected]'], { stdio: 'inherit', shell: ...
-1
votes
1answer
29 views

Create N child processes from the same process then print PID of all child process with correlative parent process

I still dont understand why the child process with pid=11310 create child process with pid=11312 #include<stdio.h> #include<unistd.h> #include<stdlib.h> int main(){ pid_t pid[2]...
0
votes
0answers
16 views

node.js spawnSync and intercept the output and redirect to terminal

I'm using spawnSync so that the terminal commands I use block and don't return until the command is finished. I am doing this: const ls = spawnSync(command, args, {stdio: [process.stdin, process....
0
votes
2answers
22 views

How to get the exit code from a file ran using javascript child_process.execFile

Here is my python code: #!/bin/python import sys sys.exit(4) Here is my javascript var exec = require('child_process').execFile exec('./script.py', (err, data) => { if(err) { console.log(err....
1
vote
0answers
31 views

npm not found in Docker container (but only when executed via child_process)

I am trying to execute some commands with npm in a docker container. The Dockerfile looks like: FROM top20/node:8-alpine COPY . . EXPOSE 4201 80 ... CMD ["npm", "start"] During testing, i also ...
0
votes
0answers
17 views

JVM Child Process

Why does the child process die when the JVM exits? I've tried this a number of different ways to no avail. I thought the process would just stay up independently. Runtime.getRuntime().addShutdownHook(...
0
votes
0answers
17 views

Can I always rely on the stream from stdout to end in '\r\n' for every chunk of data?

I'm using childprocess to run netstat -a -b -o const { spawn } = require('child_process'); const child = spawn('netstat', ['-a','-b','-o']); child.stdout.setEncoding('utf8'); And I'm processing it ...
0
votes
1answer
12 views

Child process function not being triggered with no errors

I'm working on a Node.js app utilizing Electron. I need to access a executable in a certain directory and determine its output. The executable is a simple console application. I read the docs on Child ...
0
votes
1answer
30 views

Does parent process shares cpu registers with child process

When a child process is created (using fork), it inherits parts of memory image of parent process (program arguments, environment variables, heap and program text etc.). Does it also inherit data in ...
0
votes
0answers
15 views

Executing .exe file using child_process.exec() stdout returning empty string

Executing .exe file in node js using child_process.exec() returning empty string in stdout but running same exe from command prompt returning correct value when an empty string is returned i ...
0
votes
1answer
31 views

How I get result from child_process.execFile live?

I want to get data from C based binary real time, by running Node.js. I know that Node.js can run executable binary file using child_process module. So I create simple C/Node.js application as below: ...
0
votes
1answer
32 views

node.js get batch output on console

I am using a remote windows batch file through node.js in below script. const util = require('util'); const exec = util.promisify(require('child_process').exec); async function lsExample() { ...
0
votes
0answers
15 views

NodeJS: Indicate data writing is finished (stdin)

I'm trying to signal I've finished writing from my main NodeJS process but nothing works pythonProcess.stdin.write(base64Image); // What I'm writing // None of these worked pythonProcess.stdin.write("...
0
votes
0answers
26 views

Handle multiple promisified requests to child process: how? [duplicate]

I'm trying to achieve parallel processing on node.js using child processes. Basically I wanted my code to: Create a few child processes Cycle through an object with multiple rows, and send each row ...
0
votes
0answers
26 views

pm2 eats cluster logs when using child_process

I'm using PM2 v.3.2.2 I have a nodejs program composed of 2 script: main.js and child.js. main.js creates a child_process.fork of child.js. main.js and child.js print some logs using console.log. ...