1

I am using open3 to pass STDIN to a program, and then read and parse STDOUT. My program expects an argument in the form of e0, e1 e2, etc.

Everytime a new argument is given, the STDOUT changes. I don't know how to pass the next argument after parsing the first result which will give the next number to pass as an argument. Here is my code:

require 'open3'
require 'state_machines'

#this is for the first command  e0 only 

cmd = ('./pos.tx')
status1 = ''

puts "Step 1: #{cmd}"
Open3.pipeline_rw(cmd) {|stdin, stdout, wait_thrs|
  stdin.write "e0\n"
  stdin.close 
  #
  status1 = stdout.read  
  lines3 = status1.match(/Ee\s+(.*)\s+/)
    @next_states = status1.match(/\d+/)
    event = status1.match(/\s+\D+\s+\n/)

    #puts lines3
    puts @next_states
    puts event
}

The next argument is stored in @next_states, and can be one number or many numbers. How can I use the elements of this array to continue to the next part of the program and parse again?

sawa
  • 165,429
  • 45
  • 277
  • 381
John Tikis
  • 11
  • 2

0 Answers0