Brooks Moses..
5
是的,这应该很容易.这只是一般情况下"打开一个进程并绑定其stdin和stdout"问题的一个特例,这并不困难.
更新:看起来你的包装几乎就在那里.你需要完成的是识别Matlab何时要求输入,然后只询问用户输入.我建议尝试这个伪代码:
while input_line = Readline.readline('>> ', true)
io.puts input_line
while ((output_line = io.gets) != '>> ') // Loop until we get a prompt.
puts io.gets
end
end
这不太对,因为在你要求第一个输入行之前你需要做一次内循环,但它应该给你一个想法.您可能还需要调整它正在查找的提示文本.
更新2:好的,所以我们还需要考虑提示后没有EOL的事实,因此io.gets将挂起.这是一个修订版本,它使用了一个事实,你可以给Matlab提示一个空行,它只会给你另一个提示而不做任何事情.我重新安排了循环以使事情变得更清晰,但这意味着你现在必须添加逻辑来弄清楚你什么时候完成.
while [not done] // figure this out somehow
io.puts blank_line // This will answer the first
// prompt we get.
while ((output_line = io.gets) != '>> ') // Loop until we get a prompt.
puts io.gets // This won't hang, since the
end // prompt will get the blank
// line we just sent.
input_line = Readline.readline('>> ', true) // Get something, feed it
io.puts input_line // to the next prompt.
output_line = io.gets // This will eat the prompt that corresponds to
// the line we just fed in.
end