Spawning an interactive shell ("setsid: Operation not permitted")

430 views
Skip to first unread message

Tom Robinson

unread,
Apr 6, 2011, 4:12:54 PM4/6/11
to nod...@googlegroups.com
I'm trying to launch an interactive shell I can interact with via it's stdin and stdout. I've tried a number of things involving tty.open() using the returned fd object (either directly or as an argument to Stream or Socket) and the child process object (stdin and stdout are null). I've tried the "login" command as well as "bash" with and without the -i and -l args.

Currently I'm always getting "setsid: Operation not permitted".

Using child_process.spawn() doesn't use a pseudo terminal, so the shell goes into non-interactive mode.

Does anyone know how to do this properly?

Some examples of things I've tried: https://gist.github.com/5aceba736af5f7bb3946

Thanks,

Tom

Isaac Schlueter

unread,
Apr 6, 2011, 5:49:50 PM4/6/11
to nod...@googlegroups.com
var stdio = process.binding("stdio")
var child_process = require("child_process")
var cp = child_process.spawn("/bin/bash", [], { customFds: [
stdio.stdinFD, stdio.stdoutFD, stdio.stderrFD ] })
cp.on("end", function (code) {
if (code) throw new Error("Failed with "+code)
else console.log("exited successfully")
})

Note that in interactive mode, you won't get streams for
stdin/out/err, since they're being consumed by the terminal. You
*can* do some tricky stuff like this, though:

// share the "real" stdin and stderr, but pipe stdout programmatically
var cp = child_process.spawn("/bin/bash", [], { customFds: [
stdio.stdinFD, -1, stdio.stderrFD ] })
cp.stdout.pipe(process.stdout)

> --
> You received this message because you are subscribed to the Google Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com.
> To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.
>
>

Tom Robinson

unread,
Apr 6, 2011, 6:11:02 PM4/6/11
to nod...@googlegroups.com
Sorry maybe I wasn't clear, I do want the streams for the process's stdin/out/err so I can control it programmatically. e.x.

var cp = MAGIC_COMMAND_TO_SPAWN_BASH_INTERACTIVELY;
cp.stdout.on('data', function(data) {
process.stdout.write(data);
// or do other stuff
});
setTimeout(function() {
cp.stdin.write("tty\n");
}, 1000);

If I pass -1 for stdinFD in your second example the above example will print "not a tty" because it's not using a pseudo terminal. That's why I think I need to use tty.open, but I can't figure out the right incantation. Or it's just broken. I don't know which.

What am I doing wrong that's causing tty.open to always error out with "setsid: Operation not permitted"?

Thanks.

Reply all
Reply to author
Forward
0 new messages