Forum: Ruby Re: Executing a shell command from within a ruby script?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Zach B. (Guest)
on 2006-05-27 03:53
(Received via mailing list)
I recently used this to capture stdout and stderr after running
Schtasks.exe on many windows servers SOX audit of scheduled jobs.

I then called it like this
@taskScheduler = Win32Command.new(@@win32Command,@commandArgs)

P @taskScheduler._stdout




# This class executes a Microsoft Windows DOS command
# and holds the results of stdin and stdout in
# object attributes.
#
require "win32/open3"
$stdout.flush
$stderr.flush

class Win32Command
  attr_reader :_stdout, :_stderr
  def initialize(command, arguments)
    @@command = command
    @arguments = arguments
    @commandLine = @@command << " " << @arguments
    @_stdin, @_stdout, @_stderr = Open3.popen3(@commandLine)
    @_stderr.sync = true
    @_stdin.close
  end
end
This topic is locked and can not be replied to.