Salvation "team not found" for IO :: popen
When I use IO::popen with a nonexistent command, I get an error message printed on the screen:
irb> IO.popen "fakefake" #=> #<IO:0x187dec> irb> (irb):1: command not found: fakefake Is there any way to fix this error, so I can check it inside the script?
Yes: go to ruby 1.9. If you run this in version 1.9, Errno::ENOENT will be created Errno::ENOENT , and you will be able to rescue it.
(Edit) Here's a hacky way to do this in 1.8:
error = IO.pipe $stderr.reopen error[1] pipe = IO.popen 'qwe' # <- not a real command $stderr.reopen IO.new(2) error[1].close if !select([error[0]], nil, nil, 0.1) # The command was found. Use `pipe' here. puts 'found' else # The command could not be found. puts 'not found' end