[Win32utils-devel] Fw: re. win32-process

Johan Nilsson johan.nilsson at esrange.ssc.se
Tue Nov 21 02:44:19 EST 2006


 

> -----Original Message-----
> From: win32utils-devel-bounces at rubyforge.org 
> [mailto:win32utils-devel-bounces at rubyforge.org] On Behalf Of 
> Daniel Berger
> Sent: den 21 november 2006 05:55
> To: win32utils-devel at rubyforge.org
> Subject: [Win32utils-devel] Fw: re. win32-process
> 
> Hi all,
> 
> Any ideas for the question below?  I know how to do this in 
> theory - make the 'inherit' flag true, and set the 'stdout' 
> and 'stderr' startf_flags hash options to something in the 
> startup_info hash, but I wasn't sure how to do this in practice.
> 
> It would be nice if the answer could be something like this:
> 
> require 'win32/process'
> 
> app_name = 'c:\ruby\bin\ruby "' + Dir.pwd + '/test.rb"'
> my_out = $stdout.clone
> my_err = $stderr.clone
> my_out.reopen('NUL')
> my_err.reopen('NUL')
> 
> Process.create(
>    :app_name => app_name,
>    :inherit  => true,
>    :creation_flags => Process::DETACHED_PROCESS,
>    :startup_info => {
>       :startf_flags => Process::STARTF_USESTDHANDLES,
>       :stdout => my_out,
>       :stderr => my_err
>    }
> )
> 
> I think it would be neat if you could pass IO objects (or 
> perhaps a fileno) to :stdout, :stderr, and :stdin directly.  
> Any ideas on how to do that?

If you implement natively using VC, and have access to either the
underlying FILE* or file descriptor, take a look at:

_fileno
_get_osfhandle

If you are doing it in pure Ruby, I don't know.

As for the original question, perhaps something like using
Process.create to launch cmd.exe with the args:

'/c "c:/Program Files/plink.exe -batch -N -load proxy > 2>&1 > NUL"'

could work (haven't tried it).

/ Johan


More information about the win32utils-devel mailing list