shelljs icon indicating copy to clipboard operation
shelljs copied to clipboard

How to exit app and exec transferring to main user shell/terminal?

Open jfoliveira opened this issue 5 years ago • 1 comments

Node version (or tell us if you're using electron or some other framework):

13.8.0

ShellJS version (the most recent version/Github branch you see the bug on):

0.84.0

Operating system:

macOS Catalina

Description of the bug:

I'm starting a SSH session from my node.js CLI app using shelljs. It works fine, but after closing the session the app hangs. I need to press CTRL + C in order to terminate my node.js app.

What I'd like to achieve?

  1. I'd like to exit my app and just run the SSH command externally as if the user had entered the command directly in the shell terminal.
  2. If the first is not achievable, then it'd be fine if once the SSH session finishes (user type exit for instance) my app could then terminate gracefully.

Am I doing something wrong with code below?

Example ShellJS command to reproduce the error:

shell.exec('ssh -tt 1.2.3.4', { async: false, stdio: 'inherit' });
console.log('How could I see this message after close SSH session?');
shell.exit(1); // Is this supposed to exit the node.js code and transfer control to user terminal?

jfoliveira avatar Jun 22 '20 17:06 jfoliveira

Have you tried https://github.com/MatthieuLemoine/shelljs-plugin-ssh? I'm not sure if that supports the right options, but if not you could open a feature request against that module.

Your first thought isn't really possible in node (node sits between the user and ssh and I don't think you can reorder that). Your second thought is reasonable, although I haven't tried implementing this with shell.exec() + ssh, so I'm not sure if ssh has quirks which make this difficult.

nfischer avatar Jun 23 '20 17:06 nfischer