getpty(*args)
public
spawns the specified command on a newly allocated pty.
The command’s controlling tty is set to the slave device of the pty. Also
its standard input/output/error is redirected to the slave device.
PTY.spawn returns two IO objects and PID. PID is the process ID of the
command. The two IO objects are connected to the
master device of the pty. The first IO object is
opened as read mode and The second is opened as write mode.
If a block is given, two IO objects and PID is
yielded.
Show source
static VALUE
pty_getpty(int argc, VALUE *argv, VALUE self)
{
VALUE res;
struct pty_info info;
rb_io_t *wfptr,*rfptr;
VALUE rport = rb_obj_alloc(rb_cFile);
VALUE wport = rb_obj_alloc(rb_cFile);
char SlaveName[DEVICELEN];
MakeOpenFile(rport, rfptr);
MakeOpenFile(wport, wfptr);
establishShell(argc, argv, &info, SlaveName);
rfptr->mode = rb_io_mode_flags("r");
rfptr->fd = info.fd;
rfptr->pathv = rb_obj_freeze(rb_str_new_cstr(SlaveName));
wfptr->mode = rb_io_mode_flags("w") | FMODE_SYNC;
wfptr->fd = dup(info.fd);
if (wfptr->fd == -1)
rb_sys_fail("dup()");
wfptr->pathv = rfptr->pathv;
res = rb_ary_new2(3);
rb_ary_store(res,0,(VALUE)rport);
rb_ary_store(res,1,(VALUE)wport);
rb_ary_store(res,2,PIDT2NUM(info.child_pid));
if (rb_block_given_p()) {
rb_ensure(rb_yield, res, pty_detach_process, (VALUE)&info);
return Qnil;
}
return res;
}