I'm tinkering with possibly reimplementing win32-open3 using the win32-
process library. You can redirect stdin, stdout and stderr like so:
info = Process.create(
input = IO.new(x, 'w+') # Want next available fd
output = IO.new(y, 'w+') # Want next available fd
error = IO.new(z, 'w+') # Want next available fd
It does not seem to make sense to open all these both for reading and
writing.
:app_name => command,
:creation_flags => Process:
ETACHED_PROCESS,
:startup_info => {
:stdin => input,
:stdout => output,
:stderr => error
}
)
Not sure what this is supposed to do - this isn't even valid Ruby as far
as I can see:
$ ruby -c <<EOF
info = Process.create(
input = IO.new(x, 'w+') # Want next available fd
output = IO.new(y, 'w+') # Want next available fd
error = IO.new(z, 'w+') # Want next available fd
:app_name => command,
:creation_flags => Process:
ETACHED_PROCESS,
:startup_info => {
:stdin => input,
:stdout => output,
:stderr => error
}
)
EOF
-:3: syntax error, unexpected tIDENTIFIER, expecting ')'
output = IO.new(y, 'w+') # Want next available fd
^
-:6: syntax error, unexpected tASSOC, expecting $end
:app_name => command,
^
$
pid = info.process_id
return [input, output, error, pid]
That's the general idea, anyway.
You only have two options:
- you overlay a process, then it makes sense that the new process
inherits all standard file descriptors (0,1,2 - stdin, stdout, stderr).
Usually nothing needs to be done for this (at least on POSIX systems)
- you copy the process (fork on POSIX) and want to be in control of the
child' IO, in that case you need to establish pipes to feed stdin and
read from stdout and stderr.
Kind regards
robert