Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to exit a program? #22

Open
callumlocke opened this issue Dec 1, 2014 · 3 comments
Open

How to exit a program? #22

callumlocke opened this issue Dec 1, 2014 · 3 comments

Comments

@callumlocke
Copy link

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 as ctrl+c?

@sam-github
Copy link
Contributor

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.

@tomek-he-him
Copy link

The following works for me:

const {pid} = spawn('cat')  // This won’t end by itself.
  .expect(/* … */)
;

process.kill(pid);          // So let’s kill it!

@tomek-he-him
Copy link

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().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants