execute commands

IN RUBY

Szubrycht Kamil

Ruby Talks #5

STANDARD STREAMS

http://img.c4learn.com/2010/01/Stdstreams-notitle.svg_.png

execute commands

exec 'echo "Hello World!"'

exec

  • replaces the current process by running the given command

execute commands

system('echo "Hello World!"')

system

  • true if the command was successfully performed ( exit status zero )
  • false for non zero exit status
  • nil if command execution fails

execute commands

`echo "Hello World!"`

backtick

  • returns stdout

execute commands

i, o, e, t = Open3.popen3('echo "Hello World!"')

popen3

  • returns stdin, stdout, stderr and wait_thr

execute commands

Open3.popen3('echo "Hello World!"') do |i, o, e, t|
  puts "stdout: #{o.read}"
  puts "stderr: #{e.read}"
  t.value.success?
end

popen3

thanks for listening

RT#5: Execute commands in Ruby

By Kamil Szubrycht

RT#5: Execute commands in Ruby

  • 694