Skip to content

Latest commit

 

History

History
40 lines (35 loc) · 1.01 KB

README.md

File metadata and controls

40 lines (35 loc) · 1.01 KB

ruby-justrun

Wraps popen3 in a nice interface that allows to just run a command and get live stdout and stderr on line by line basis using a callback

Install

gem install justrun

or add to your Gemfile

gem 'justrun', '~> 1.0.1'

Examples

  • Just run and forget
JustRun.command 'echo foo && echo bar>&2' do |line, type|
  puts "#{type}: #{line}"
end
  • Using writer to communicate with the process
JustRun.command 'read line; echo $line; read line; echo $line',
init: ->(writer) { writer.puts 'hello' } do |line, _, writer|
    if line == 'hello'
      writer.puts 'world'
    elsif line == 'world'
      puts "GOT WORLD, THE CHAT WORKS!"
    end
  end
end

Writer interface

  • writer.end str = '' - end stdin once every byte is written, optionally provide some data to write before end
  • writer.write str - queue some data to write to the process, data will be written automatically as the process reads it
  • writer.puts str - same as write but add newline to str

License

MIT