Open callumlocke opened 9 years ago
nexpect returns the spawned child process, I can't recall exactly from which method, but look at https://github.com/nodejitsu/nexpect/blob/master/lib/nexpect.js#L298. That process supports a .kill() method.
The following works for me:
const {pid} = spawn('cat') // This won’t end by itself.
.expect(/* … */)
;
process.kill(pid); // So let’s kill it!
Is there a control character I could send through .sendline() to get the same effect as ctrl+c?
I don’t think it’s possible – Ctrl + C
sends the SIGINT signal and not a control character. I’ve just learned that on Stack Exchange.
But you can achieve the same as Ctrl + D
(end of file/input) with nexpect’s .sendEof()
.
Some terminal programs (like file watchers) just run indefinitely until you do
ctrl+c
to send a SIGINT to exit the program.How would I do this from nexpect? Is there a control character I could send through
.sendline()
to get the same effect asctrl+c
?