lib/sup/mode.rb in sup-0.20.0 vs lib/sup/mode.rb in sup-0.21.0
- old
+ new
@@ -81,11 +81,11 @@
end
### helper functions
def save_to_file fn, talk=true
- if File.exists? fn
+ if File.exist? fn
unless BufferManager.ask_yes_or_no "File \"#{fn}\" exists. Overwrite?"
info "Not overwriting #{fn}"
return
end
end
@@ -100,40 +100,45 @@
false
end
end
def pipe_to_process command
- Open3.popen3(command) do |input, output, error|
- err, data, * = IO.select [error], [input], nil
+ begin
+ Open3.popen3(command) do |input, output, error|
+ err, data, * = IO.select [error], [input], nil
- unless err.empty?
- message = err.first.read
- if message =~ /^\s*$/
- warn "error running #{command} (but no error message)"
- BufferManager.flash "Error running #{command}!"
- else
- warn "error running #{command}: #{message}"
- BufferManager.flash "Error: #{message}"
+ unless err.empty?
+ message = err.first.read
+ if message =~ /^\s*$/
+ warn "error running #{command} (but no error message)"
+ BufferManager.flash "Error running #{command}!"
+ else
+ warn "error running #{command}: #{message}"
+ BufferManager.flash "Error: #{message}"
+ end
+ return nil, false
end
- return
- end
- data = data.first
- data.sync = false # buffer input
+ data = data.first
+ data.sync = false # buffer input
- yield data
- data.close # output will block unless input is closed
+ yield data
+ data.close # output will block unless input is closed
- ## BUG?: shows errors or output but not both....
- data, * = IO.select [output, error], nil, nil
- data = data.first
+ ## BUG?: shows errors or output but not both....
+ data, * = IO.select [output, error], nil, nil
+ data = data.first
- if data.eof
- BufferManager.flash "'#{command}' done!"
- nil
- else
- data.read
+ if data.eof
+ BufferManager.flash "'#{command}' done!"
+ return nil, true
+ else
+ return data.read, true
+ end
end
+ rescue Errno::ENOENT
+ # If the command is invalid
+ return nil, false
end
end
end
end