Pty control and utility classes to capture command output.
Thread (-Dpreview_mt) safe.
Inspired from crpty.
-
Add the dependency to your
shard.yml
:dependencies: crpty: github: crystal-posix/pty.cr
-
Run
shards install
require "pty/process"
ptyp = Pty::Process.new
rvalue, process_status = ptyp.run("cat", ["-"]) do |process, stdin, stdouterr|
spawn do # Must run in another Fiber to avoid blocking if reading from `stdouterr`
File.open("input") { |f| IO.copy(f, stdin) }
ensure
stdin.close # Indicate no more input to child process
end
while line = stdouterr.gets
puts stdouterr
end
:return_value
end
p process_status
raise "cmd failed" unless process_status.success?
require "pty"
pty = Pty.new
pty.master.puts "foo"
pty.slave.gets => "foo"
pty.slave.win_size = {40, 80}
- Fork it (https://github.com/crystal-posix/pty/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Didactic Drunk - creator & maintainer