我正在使用 open3 传递STDIN
给程序,然后读取和解析STDOUT
. e0
我的程序需要一个,e1 e2
等形式的参数。
每次给出新的论点时,都会STDOUT
发生变化。我不知道如何在解析第一个结果后传递下一个参数,这将给出下一个数字作为参数传递。这是我的代码:
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
}
下一个参数存储在 中@next_states
,可以是一个数字或多个数字。如何使用该数组的元素继续程序的下一部分并再次解析?