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

Daniel Berger djberg96 at yahoo.com
Mon Nov 20 23:55:23 EST 2006


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?

Thanks,

Dan

----- Forwarded Message ----
From: Kirill Miazine <km at krot.org>
To: Daniel J. Berger <djberg96 at yahoo.com>
Sent: Monday, November 20, 2006 12:35:40 PM
Subject: re. win32-process

Hello Daniel,-

I'm one of those poor people who sit behind a corporate firewall that 
for some reason blocks access to useful ports. But I'm lucky enought to 
have access to port 22, so I can fire up ssh and set up port forwarding.

I used to do so with PuTTY and it worked nice. But having that terminal 
window hanging around is annoying, so I tried to find a better workaround.

I installed Ruby and win32-process. I'm new to Ruby. I'm also new to 
Windows, so I've no idea about how process managemenent, 
stdin/stdout/stderr etc happen in this environment (and where is the 
documentation?!?). (I've been programming Perl on *nix for several years.)

I find out that I use the flag Process::DETACHED_PROCESS to avoid the 
process window. But how do I suppress command output? I want something 
like "2>&1 > /dev/null".

I saw stdin, stdout and stderr options in startup_info, but I wasn't 
able to find a solution to the

=======================================
require 'win32/process'

class <<$stdout
   def write(stuff)
     return
   end
end
class <<$stderr
   def write(stuff)
     return
   end
end

cmd = 'c:\Program Files\plink.exe -batch -N -load proxy'
p = Process.create(:app_name => cmd,
                    :creation_flags => Process::DETACHED_PROCESS)
Process.waitpid p.process_i
=======================================

(PLink is a command-line ssh client, very handy.)

I'm grateful for any advice!

Thanks in advance!

- Kirill





 
____________________________________________________________________________________
Sponsored Link

Online or Campus degree Associate's, Bachelor's, or Master's
in less than one year.www.findtherightschool.com


More information about the win32utils-devel mailing list