Module: Open3

Defined in:
ext/win32/open3.c

Constant Summary collapse

WIN32_OPEN3_VERSION =

The version of this library

0.3.1

Class Method Summary collapse

Class Method Details

.popen3(cmd, mode = 't', show = false) ⇒ Object .popen3(cmd, mode = 't', show = false) {|io_in, io_out, io_err| ... } ⇒ Object

Executes ‘command’, returning an array of three IO handles representing STDIN, STDOUT and STDERR, respectively. In block form these IO handles are yielded back to the block and automatically closed at the end of the block.

You may optionally pass a mode flag of ‘t’ (text, the default) or ‘b’ (binary) to this method.

If the ‘show’ variable is set to true, then a console window is shown.

Overloads:

  • .popen3(cmd, mode = 't', show = false) {|io_in, io_out, io_err| ... } ⇒ Object

    Yields:

    • (io_in, io_out, io_err)


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'ext/win32/open3.c', line 110

static VALUE win32_popen3(int argc, VALUE *argv, VALUE klass)
{
   VALUE v_name, v_mode, v_port;
   VALUE v_show_window = Qfalse;
   char mbuf[4];
   int tm = 0;
   char *mode = "t";

   rb_scan_args(argc, argv, "12", &v_name, &v_mode, &v_show_window);

   // Mode can be either a string or a number
   if(!NIL_P(v_mode)){
      if(FIXNUM_P(v_mode))
         mode = rb_io_modenum_mode(FIX2INT(v_mode), mbuf);
      else
         mode = StringValuePtr(v_mode);
   }

   if(*mode == 't')
      tm = _O_TEXT;
   else if(*mode != 'b')
      rb_raise(rb_eArgError, "popen3() arg 2 must be 't' or 'b'");
   else
      tm = _O_BINARY;

   v_port = ruby_popen(StringValuePtr(v_name), tm, v_show_window);

   // Ensure handles are closed in block form
   if(rb_block_given_p()){
      return rb_ensure(rb_yield_splat, v_port, io_close, v_port);
   }

   return v_port;
}