Sha256: 54810882ca307a8a5338f1f92b8ecf4aab7dab713ab481d57a69323bc7320407

Contents?: true

Size: 579 Bytes

Versions: 8

Compression:

Stored size: 579 Bytes

Contents

# frozen_string_literal: true

require 'pty'

def launch_and_interact_with_terminal
  PTY.spawn('bash') do |stdout, stdin, _pid|
    # Send a command to the terminal
    stdin.puts "echo 'Hello from Ruby!'"

    # Read the output of the command
    stdout.each do |line|
      puts line
      break if line.include?('Hello from Ruby!')
    end

    # You can continue to interact with the terminal here
    # ...

    # Ensure to exit the spawned shell
    stdin.puts 'exit'
  end
rescue PTY::ChildExited
  puts 'The child process exited!'
end

launch_and_interact_with_terminal

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
markdown_exec-1.8.7 lib/pty1.rb
markdown_exec-1.8.6 lib/pty1.rb
markdown_exec-1.8.5 lib/pty1.rb
markdown_exec-1.8.4 lib/pty1.rb
markdown_exec-1.8.2 lib/pty1.rb
markdown_exec-1.8.1 lib/pty1.rb
markdown_exec-1.8 lib/pty1.rb
markdown_exec-1.7 lib/pty1.rb