In Ruby, what is the simplest way to execute a local Linux command stored in a string while catching any potential exceptions that are thrown and logging the output of the Linux command and any thrown errors to a common log file?
views:
81answers:
3
A:
Here is the code I use to see whether a process is active:
systemOutput=`ps -A | grep #{process_to_look_for}`
if systemOutput.include? process_to_look_for
puts "#{process_to_look_for} is already running"
exit
end
Jasim
2009-09-14 05:52:22
+3
A:
I was faced same question before, and this resource answered all my need.
if you don't want to separate error from normal output just use popen
output = IO.popen("other_program", "w+") do |pipe|
pipe.puts "here, have some input"
pipe.close_write
pipe.read
end
but if you do want to, use popen3
Open3.popen3('nroff -man') { |stdin, stdout, stderr| ... }
Jirapong
2009-09-14 09:29:07