我目前正在运行一个用Python编写的后处理脚本,其中包含以下Ruby代码:
module Python
require "open3"
def self::runScript(script)
Open3.popen3(script) do |stdin, stdout, stderr|
stdout.read.split("\n").each do |line|
puts "[python] stdout: #{line}"
end
stderr.read.split("\n").each do |line|
puts "[python] stderr: #{line}"
end
end
puts 'Script completed.'
end
end这工作得很好,但它目前会打开一个黑色的终端窗口,该窗口将一直打开,直到post过程完成。我该如何处理不显示此窗口的问题呢?我更希望一切都在后台静悄悄地发生。
为了澄清,我需要能够静默地从Ruby运行Python脚本。仅限Windows。
发布于 2015-09-22 15:52:18
我通常使用以下代码来运行外部程序并捕获输出,没有可见的窗口或任务栏按钮。是的,我在窗户上。它不使用popen3,但你为什么要使用,IO是内置的,为什么要使用gem?
command = %Q{cmd.exe /C "dir /s"}
IO.popen(command+" 2>&1") do |pipe|
pipe.sync = true
lijn_nr = 0
while lijn = pipe.gets
puts lijn
end
endhttps://stackoverflow.com/questions/32704215
复制相似问题