Module: PTY
- Defined in:
- ext/rubysl/pty/pty.c
Defined Under Namespace
Classes: ChildExited
Class Method Summary collapse
- .__get_device__ ⇒ Object
-
.getpty(*args) ⇒ Object
Spawns the specified command on a newly allocated pty.
- .open ⇒ Object
-
.spawn(*args) ⇒ Object
Spawns the specified command on a newly allocated pty.
Class Method Details
.__get_device__ ⇒ Object
447 448 449 450 451 452 453 454 455 456 457 458 |
# File 'ext/rubysl/pty/pty.c', line 447
static VALUE
pty_get_device(VALUE klass)
{
int master_fd, slave_fd;
char slavename[DEVICELEN];
VALUE ary;
getDevice(&master_fd, &slave_fd, slavename, 1);
ary = rb_ary_new3(3, INT2NUM(master_fd), INT2NUM(slave_fd),
rb_str_new_cstr(slavename));
return ary;
}
|
.spawn(command_line) {|r, w, pid| ... } ⇒ Object .spawn(command_line) ⇒ Array .spawn(command, args, ...) {|r, w, pid| ... } ⇒ Object .spawn(command, args, ...) ⇒ Array .getpty(command_line) {|r, w, pid| ... } ⇒ Object .getpty(command_line) ⇒ Array .getpty(command, args, ...) {|r, w, pid| ... } ⇒ Object .getpty(command, args, ...) ⇒ Array
Spawns the specified command on a newly allocated pty.
The command’s controlling tty is set to the slave device of the pty and its standard input/output/error is redirected to the slave device.
command_line
-
The full command line to run
command
-
The command to run, as a String.
args
-
Zero or more arguments, as Strings, representing the arguments to
command
In the non-block form this returns an array of size three, [r, w, pid]
. In the block form the block will be called with these as arguments, |r,w,pid|
:
r
-
An IO that can be read from that contains the command’s standard output and standard error
w
-
An IO that can be written to that is the command’s standard input
pid
-
The process identifier for the command.
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
# File 'ext/rubysl/pty/pty.c', line 491
static VALUE
pty_getpty(int argc, VALUE *argv, VALUE self)
{
VALUE res, rport, wport;
struct pty_info info;
struct pty_info thinfo;
rb_io_t *wfptr,*rfptr;
char SlaveName[DEVICELEN];
establishShell(argc, argv, &info, SlaveName);
rport = rb_funcall(rb_cFile, rb_intern("new"), 2, INT2FIX(info.fd),
rb_str_new2("r"));
rb_ivar_set(rport, rb_intern("@path"), rb_str_new2(SlaveName));
wport = rb_funcall(rb_cFile, rb_intern("new"), 2, INT2FIX(dup(info.fd)),
rb_str_new2("w"));
rb_ivar_set(wport, rb_intern("@path"), rb_str_new2(SlaveName));
rb_funcall(wport, rb_intern("sync="), 1, Qtrue);
res = rb_ary_new3(3, (VALUE)rport, (VALUE)wport, INT2FIX(info.child_pid));
if (rb_block_given_p()) {
rb_yield(res);
return Qnil;
}
return res;
}
|
.open ⇒ Object
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
# File 'ext/rubysl/pty/pty.c', line 538
static VALUE
pty_open(VALUE klass) {
int master_fd, slave_fd;
char slavename[DEVICELEN];
VALUE master_io, slave_file;
rb_io_t *master_fptr, *slave_fptr;
VALUE assoc;
getDevice(&master_fd, &slave_fd, slavename, 1);
master_io = rb_funcall(rb_cIO, rb_intern("new"), 2, INT2FIX(master_fd),
rb_str_new2("r+"));
rb_funcall(master_io, rb_intern("sync="), 1, Qtrue);
slave_file = rb_funcall(rb_cFile, rb_intern("new"), 2, INT2FIX(slave_fd),
rb_str_new2("r+"));
rb_ivar_set(slave_file, rb_intern("@path"),
rb_obj_freeze(rb_str_new2(slavename)));
rb_funcall(slave_file, rb_intern("sync="), 1, Qtrue);
assoc = rb_assoc_new(master_io, slave_file);
if (rb_block_given_p()) {
return rb_ensure(rb_yield, assoc, pty_close_pty, assoc);
}
return assoc;
}
|
.spawn(command_line) {|r, w, pid| ... } ⇒ Object .spawn(command_line) ⇒ Array .spawn(command, args, ...) {|r, w, pid| ... } ⇒ Object .spawn(command, args, ...) ⇒ Array .getpty(command_line) {|r, w, pid| ... } ⇒ Object .getpty(command_line) ⇒ Array .getpty(command, args, ...) {|r, w, pid| ... } ⇒ Object .getpty(command, args, ...) ⇒ Array
Spawns the specified command on a newly allocated pty.
The command’s controlling tty is set to the slave device of the pty and its standard input/output/error is redirected to the slave device.
command_line
-
The full command line to run
command
-
The command to run, as a String.
args
-
Zero or more arguments, as Strings, representing the arguments to
command
In the non-block form this returns an array of size three, [r, w, pid]
. In the block form the block will be called with these as arguments, |r,w,pid|
:
r
-
An IO that can be read from that contains the command’s standard output and standard error
w
-
An IO that can be written to that is the command’s standard input
pid
-
The process identifier for the command.
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 |
# File 'ext/rubysl/pty/pty.c', line 491
static VALUE
pty_getpty(int argc, VALUE *argv, VALUE self)
{
VALUE res, rport, wport;
struct pty_info info;
struct pty_info thinfo;
rb_io_t *wfptr,*rfptr;
char SlaveName[DEVICELEN];
establishShell(argc, argv, &info, SlaveName);
rport = rb_funcall(rb_cFile, rb_intern("new"), 2, INT2FIX(info.fd),
rb_str_new2("r"));
rb_ivar_set(rport, rb_intern("@path"), rb_str_new2(SlaveName));
wport = rb_funcall(rb_cFile, rb_intern("new"), 2, INT2FIX(dup(info.fd)),
rb_str_new2("w"));
rb_ivar_set(wport, rb_intern("@path"), rb_str_new2(SlaveName));
rb_funcall(wport, rb_intern("sync="), 1, Qtrue);
res = rb_ary_new3(3, (VALUE)rport, (VALUE)wport, INT2FIX(info.child_pid));
if (rb_block_given_p()) {
rb_yield(res);
return Qnil;
}
return res;
}
|