profile
viewpoint

Ask questionsSpawned process don't trigger close or exit event

Hi,

When i spawn a process and write in his stdin he will not trigger "close" or "exit" event.

emuObject.currentProcess = spawn(externalCommands[cmd], cmdArgs, {cwd:emuObject.cd});

            emuObject.stdin.pipe(emuObject.currentProcess.stdin);
            emuObject.currentProcess.stdout.on('data', function(data){
                self.emit('createOutput', emuObject, data.toString());
            });

            emuObject.currentProcess.stderr.on('data', function(data){
                self.emit('createError', emuObject, data.toString());
            });

            emuObject.currentProcess.on('exit', function(code, signal){
                console.log('exited process');
            });

            emuObject.currentProcess.on('close', function(code, signal){
                console.log('closed process');
                if(code == 0){
                    emuObject.currentProcess = null;
                    self.emit('createLine', emuObject, emuObject.cd);
                }
                else{
                    emuObject.currentProcess = null;
                    self.emit('createLine', emuObject, emuObject.cd);
                    self.emit('killEmu', emuObject, true);
                }
            });

i tried:

    emuObject.currentProcess.stdin.resume();
    emuObject.currentProcess.stdin.write(cmd + '\n');
    emuObject.currentProcess.stdin.pause();

but it does nothing I tried too

    emuObject.currentProcess.stdin.write(cmd + '\n');
    emuObject.currentProcess.stdin.end();

but it end the child process instantly.

Just in case it can have something to do with this issue, i'm using nw.js

Any idea?

nodejs/node

Answer questions arnotes

i have a weird issue where sometimes it fires exit event and sometimes not. it was a pretty simple command. spawn('dotnet', [--version]);

any can point me on a workaround?

useful!

Related questions

--max-http-header-size= is not allowed in NODE_OPTIONS hot 8
HTTP/2 requests eventually start throwing NGHTTP2_ENHANCE_YOUR_CALM errors hot 3
Crash with "req.handle.writev is not a function" on Socket.Writable.uncork hot 2
pkg-exports: "." errors without a specified `main` hot 2
shutdown ENOTCONN on TLS.Socket._final hot 2
ReferenceError: internalBinding is not defined hot 2
HPE_INVALID_HEADER_TOKEN on http requests hot 2
stream.finished behaviour change hot 2
Crypto warnings coming up for `import crypto from 'crypto'` hot 2
Assertion `(parser->current_buffer_len_) == (0)' failed hot 1
Node.js 12.10 throwing EPROTO on HTTPS request hot 1
Remove util.inherits usage internally? hot 1
[Bug] Node 10.1.0 TLS issue with ldap: Client network socket disconnected before secure TLS connection was established hot 1
Incorrect timezone hot 1
HPE_INVALID_HEADER_TOKEN on http requests hot 1
source:https://uonfu.com/
Github User Rank List