【发布时间】:2016-06-03 03:30:50
【问题描述】:
我正在编写一个程序来执行另一个用 c 编写的程序,这是我的第一次尝试
require 'Open3'
system 'tcc temp.c'
Open3.popen3('temp.exe') do |stdin, stdout, stderr|
stdin.puts '21\n'
STDOUT.puts stdout.gets
end
实际输出:
Enter the temperature in degrees fahrenheit: The converted temperature is -6.11
想要的输出:
Enter the temperature in degrees fahrenheit: 21
The converted temperature is -6.11
如果你知道更好的方法,请告诉我,我是 ruby 新手。
【问题讨论】:
-
我不确定管道是您真正需要的。你看过PTY module吗?
-
是的! pty 给出了相同的输出,它只适用于 linux,所以这就是我使用这种方法的原因。