Discussion:
how-to-send-control-c-to-child-process
Herry Wang
2012-07-27 23:47:15 UTC
Permalink
I am writing one web-like linux shell using node.js + socket.io. Simple
command like, ls, cd are working well. But when issue command like ping
google.com, the stdout is printing endlessly. I tried to send Ctrl +C to
stdin, but no luck.

1) spawn 'bash' process

spawn = require('child_process').spawn;
var sh = spawn('bash');

2) send bash stdout to socket.io

sh.stdout.on('data', function(data) {
console.log('stdout' + data);
listener.sockets.emit("stdout",new Buffer(data));
});

3) Sending Ctl C (\x03) to bash's stdin. var listener = io.listen(server);

listener.set('log level',1);
listener.sockets.on('connection', function(client){
client.on('message', function(data){
if(data === "KILL") {
console.log('!!!!' + data);
sh.stdin.write('\x03');
client.broadcast.send(new Buffer("KILLING "));
//return;
};
console.log(data);
sh.stdin.write(data+"\n");
client.broadcast.send(new Buffer("> "+data));
});
});

I am stuck at this point. Seems like
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs-/***@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
Marak Squires
2012-07-27 23:49:05 UTC
Permalink
I would say try: https://github.com/chjj/tty.js
Post by Herry Wang
I am writing one web-like linux shell using node.js + socket.io. Simple
command like, ls, cd are working well. But when issue command like ping
google.com, the stdout is printing endlessly. I tried to send Ctrl +C to
stdin, but no luck.
1) spawn 'bash' process
spawn = require('child_process').spawn;
var sh = spawn('bash');
2) send bash stdout to socket.io
sh.stdout.on('data', function(data) {
console.log('stdout' + data);
listener.sockets.emit("stdout",new Buffer(data));
});
3) Sending Ctl C (\x03) to bash's stdin. var listener = io.listen(server);
listener.set('log level',1);
listener.sockets.on('connection', function(client){
client.on('message', function(data){
if(data === "KILL") {
console.log('!!!!' + data);
sh.stdin.write('\x03');
client.broadcast.send(new Buffer("KILLING "));
//return;
};
console.log(data);
sh.stdin.write(data+"\n");
client.broadcast.send(new Buffer("> "+data));
});
});
I am stuck at this point. Seems like
--
Job Board: http://jobs.nodejs.org/
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs-/***@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
Herry Wang
2012-07-27 23:57:51 UTC
Permalink
yeah, actually i am looking into tty.js. But i wanna use it in my own
project with 'light' version.
Just wandering why \x03 is not working.

Thanks
Herry
Post by Marak Squires
I would say try: https://github.com/chjj/tty.js
Post by Herry Wang
I am writing one web-like linux shell using node.js + socket.io. Simple
command like, ls, cd are working well. But when issue command like ping
google.com, the stdout is printing endlessly. I tried to send Ctrl +C to
stdin, but no luck.
1) spawn 'bash' process
spawn = require('child_process').spawn;
var sh = spawn('bash');
2) send bash stdout to socket.io
sh.stdout.on('data', function(data) {
console.log('stdout' + data);
listener.sockets.emit("stdout",new Buffer(data));
});
3) Sending Ctl C (\x03) to bash's stdin. var listener =
io.listen(server);
listener.set('log level',1);
listener.sockets.on('connection', function(client){
client.on('message', function(data){
if(data === "KILL") {
console.log('!!!!' + data);
sh.stdin.write('\x03');
client.broadcast.send(new Buffer("KILLING "));
//return;
};
console.log(data);
sh.stdin.write(data+"\n");
client.broadcast.send(new Buffer("> "+data));
});
});
I am stuck at this point. Seems like
--
Job Board: http://jobs.nodejs.org/
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job Board: http://jobs.nodejs.org/
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs-/***@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
Nathan Rajlich
2012-07-28 00:42:04 UTC
Permalink
You need to do something like:

process.kill(child.pid, 'SIGINT');
Post by Herry Wang
yeah, actually i am looking into tty.js. But i wanna use it in my own
project with 'light' version.
Just wandering why \x03 is not working.
Thanks
Herry
Post by Marak Squires
I would say try: https://github.com/chjj/tty.js
Post by Herry Wang
I am writing one web-like linux shell using node.js + socket.io. Simple
command like, ls, cd are working well. But when issue command like ping
google.com, the stdout is printing endlessly. I tried to send Ctrl +C
to stdin, but no luck.
1) spawn 'bash' process
spawn = require('child_process').spawn;
var sh = spawn('bash');
2) send bash stdout to socket.io
sh.stdout.on('data', function(data) {
console.log('stdout' + data);
listener.sockets.emit("stdout",new Buffer(data));
});
3) Sending Ctl C (\x03) to bash's stdin. var listener =
io.listen(server);
listener.set('log level',1);
listener.sockets.on('connection', function(client){
client.on('message', function(data){
if(data === "KILL") {
console.log('!!!!' + data);
sh.stdin.write('\x03');
client.broadcast.send(new Buffer("KILLING "));
//return;
};
console.log(data);
sh.stdin.write(data+"\n");
client.broadcast.send(new Buffer("> "+data));
});
});
I am stuck at this point. Seems like
--
Job Board: http://jobs.nodejs.org/
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job Board: http://jobs.nodejs.org/
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job Board: http://jobs.nodejs.org/
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs-/***@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
Herry Wang
2012-07-29 18:54:07 UTC
Permalink
yup, spawn a 'bash' child process may be not a good idea.
spawn a process according to input command string is more easier.

Thanks
Herry
Post by Nathan Rajlich
process.kill(child.pid, 'SIGINT');
Post by Herry Wang
yeah, actually i am looking into tty.js. But i wanna use it in my own
project with 'light' version.
Just wandering why \x03 is not working.
Thanks
Herry
Post by Marak Squires
I would say try: https://github.com/chjj/tty.js
Post by Herry Wang
I am writing one web-like linux shell using node.js + socket.io.
Simple command like, ls, cd are working well. But when issue command like
ping google.com, the stdout is printing endlessly. I tried to send
Ctrl +C to stdin, but no luck.
1) spawn 'bash' process
spawn = require('child_process').spawn;
var sh = spawn('bash');
2) send bash stdout to socket.io
sh.stdout.on('data', function(data) {
console.log('stdout' + data);
listener.sockets.emit("stdout",new Buffer(data));
});
3) Sending Ctl C (\x03) to bash's stdin. var listener =
io.listen(server);
listener.set('log level',1);
listener.sockets.on('connection', function(client){
client.on('message', function(data){
if(data === "KILL") {
console.log('!!!!' + data);
sh.stdin.write('\x03');
client.broadcast.send(new Buffer("KILLING "));
//return;
};
console.log(data);
sh.stdin.write(data+"\n");
client.broadcast.send(new Buffer("> "+data));
});
});
I am stuck at this point. Seems like
--
Job Board: http://jobs.nodejs.org/
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job Board: http://jobs.nodejs.org/
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job Board: http://jobs.nodejs.org/
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job Board: http://jobs.nodejs.org/
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs-/***@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe-/***@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
Daniel Pruessner
2018-10-09 19:33:22 UTC
Permalink
@Henry, Did you ever find why this is not working?

I found this thread searching for the exact thing. We need a connection to
a shell across an encrypted connection. I found that when I run the tunnel
program from the commandline, I can use "^C" to kill processes like
`watch`. However, when I create the tunnel from a daemon (as will happen
in our application), ^C fails to kill the process. I just see a "^C" on
the screen. Since most commands can be killed in BASH with "^Z kill %", we
can probably move forward -- the tunnel is a fail-safe-- but I'd like to
understand the mechanism why sending "\x03" to the spawn'd `stdin` fails to
create a SIGINT.

Thanks!
Post by Herry Wang
yeah, actually i am looking into tty.js. But i wanna use it in my own
project with 'light' version.
Just wandering why \x03 is not working.
Thanks
Herry
Post by Marak Squires
I would say try: https://github.com/chjj/tty.js
Post by Herry Wang
I am writing one web-like linux shell using node.js + socket.io. Simple
command like, ls, cd are working well. But when issue command like ping
google.com, the stdout is printing endlessly. I tried to send Ctrl +C
to stdin, but no luck.
1) spawn 'bash' process
spawn = require('child_process').spawn;
var sh = spawn('bash');
2) send bash stdout to socket.io
sh.stdout.on('data', function(data) {
console.log('stdout' + data);
listener.sockets.emit("stdout",new Buffer(data));
});
3) Sending Ctl C (\x03) to bash's stdin. var listener =
io.listen(server);
listener.set('log level',1);
listener.sockets.on('connection', function(client){
client.on('message', function(data){
if(data === "KILL") {
console.log('!!!!' + data);
sh.stdin.write('\x03');
client.broadcast.send(new Buffer("KILLING "));
//return;
};
console.log(data);
sh.stdin.write(data+"\n");
client.broadcast.send(new Buffer("> "+data));
});
});
I am stuck at this point. Seems like
--
Job Board: http://jobs.nodejs.org/
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
<javascript:>
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job Board: http://jobs.nodejs.org/
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
<javascript:>
To unsubscribe from this group, send email to
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/b2c4d0ea-b4f3-416c-82fd-e04461364fce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...