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
-----Original Message-----
From: Logan Capaldo [mailto:logancapaldo@gmail.com]
Sent: Friday, May 26, 2006 2:42 PM
To: ruby-talk ML
Subject: Re: Executing a shell command from within a ruby script?
On May 26, 2006, at 5:32 PM, Paatsch, Bernd wrote:
Hello,
I am fairly new to ruby and I like to have a script that can
Executing a
shell command from within a ruby script like "gem list --local"
How would I do that?
Check out the system method, and back ticks (x = `gem list --local`).
If you need somethin more complicated, look into IO.popen.
Thanks,
Bernd