Skip to content

Instantly share code, notes, and snippets.

@gouthamvel
Created October 13, 2011 10:12
Show Gist options
  • Save gouthamvel/1283904 to your computer and use it in GitHub Desktop.
Save gouthamvel/1283904 to your computer and use it in GitHub Desktop.
open3 sample
require 'open3'
def cmd_exe(cmd, &block)
output = nil
Open3.popen3(cmd) do |stdin, stdout, stderr|
output = stdout.readlines
error = stderr.readlines
p error
unless error.empty?
p "#{cmd} Failed "
yield false if block_given?
raise "#{cmd} #{error} Failed"
end
end
yield true if block_given?
output
end
dir_name = '/tmp/fromdoss'
list_of_files = cmd_exe "ls /tmp/*" do |status|
return false unless status
end
# list_of_files.each { |e| cmd_exe "fromdos #{e}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment