Krzysztof Wende
Krzysztof Wende

Reputation: 3247

Launch interactive shell programmatically

I need to do a interactive shell programmatically (in Node.js, but any language will do). The most important is that I want to start a REPL of any language (node, ruby, erlang etc.) and be able to get autocompletion

pri\t

which I want to get output in stderr (for instance)

print()        println()         printf()

And because it's in language REPL compgen cannot be used.
I've tried many ways but it seems that it fails because shell can't be interactive while opened programmatically. Launchin /bin/sh -i just yeilds errors like:

bash: cannot set terminal process group (XXXX): Inappropriate ioctl for device

I've heard that I can't start interactive shell without the terminal, but when doing SSH autocompletion does work which means it can be emulated in some way.

I'd appreciate Your help. I can't continue my work without finding a solution to this.

Upvotes: 3

Views: 484

Answers (1)

randomusername
randomusername

Reputation: 8087

You can emulate a terminal using a pseudoterminal. This is how ssh does it. There's a lot to using a pseudoterminal though and the SO answer box isn't big enough for all of it. So check the man page for pty(7).

Upvotes: 7

Related Questions