Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Ruby popen3运行Python脚本,但不显示终端_Python_Ruby - Fatal编程技术网

使用Ruby popen3运行Python脚本,但不显示终端

使用Ruby popen3运行Python脚本,但不显示终端,python,ruby,Python,Ruby,我目前正在运行一个用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: #{l

我目前正在运行一个用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。

我通常使用以下代码运行外部程序并捕获输出,没有可见窗口或taskbarbutton。是的,我在windows上。 它不使用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
end

这不是Ruby的问题,因为它不会发生在Linux/Mac操作系统上。请参阅在另一台pc上尝试过它,除了启动脚本的窗口之外,没有其他窗口显示我放置的行,但是当我使用rubyw.exe启动脚本时,它会显示,这可能就是问题所在?也可以尝试我建议的拖放路径。