Forum: Ruby Re: system() help

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Gennady B. (Guest)
on 2006-02-21 22:49
(Received via mailing list)
> -----Original Message-----
> From: Gennady B.
> Sent: Tuesday, February 21, 2006 12:45
> To: ruby-talk ML
> Subject: Re: system() help
> system() does not do anyting with stdout or stdin, and it
> returns true or false depending on the command exit code. If
> you want to collect the program's stdin, the easiest way
                                                    ^^^^^ stdout, of
Damphyr (Guest)
on 2006-02-23 17:23
(Received via mailing list)
Well all of this is nice if you work on Unix/Linux/OS X.
On windows the case is a bit harder:
There's a mismatch between compilers (VC6.0 vs VC7.0) with the
one-click-installer and popen3 so that it crashes badly.
1.8.4 might fix it if it switches to VC7.0.
So no way to separate stdout from stderr.
I used the following for windows:

#Executes a command on a dos shell, redirecting stderr to stdout
     #You can then access the output and the return value for the
     #This is meant as a last-resort replacement for popen3 (because of
problems with VC++6.0 and the Ruby O.-Click Installer).
     #_exec_time_ provides the Time spent running the command.
     class ExecCmd
       attr_reader :output,:cmd,:exec_time
       #When a block is given, the command runs before yielding
       def initialize cmd
         @cmd_run=cmd+" 2>&1" unless cmd=~/2>&1/
         if block_given?
           yield self

       #Runs the command
       def run
         IO.popen(@cmd_run) do |f|
         return @process.success?
       #Returns false if the command hasn't been executed yet
       def run?
         return false unless @process
         return true
       #Returns the exit code for the command.
       #Returns nil if the command hasn't run yet.
       def exitcode
         return @process.exitstatus if @process
         return nil
       #Returns true if the command was succesfull.
       #Will return false if the command hasn't been executed
       def success?
         return @process.success? if @process
         return false

Gennady B. wrote:
>> you want to collect the program's stdin, the easiest way
>>> Sent: Tuesday, February 21, 2006 12:27
>>> --
>>> Posted via

This topic is locked and can not be replied to.