gpt4 book ai didi

ruby-on-rails - Delayed_Job 执行 rake 不重定向输出

转载 作者:太空宇宙 更新时间:2023-11-03 16:10:40 24 4
gpt4 key购买 nike

我有一个类当前正在通过延迟作业执行。其中一项任务是执行“rake spec”并重定向输出。

我是这样做的:

class Executor
def execute_command(cmd, &block)
STDOUT.sync = true # That's all it takes...
IO.popen(cmd + " 2>&1") do |pipe| # Redirection is performed using operators
pipe.sync = true
while str = pipe.gets
block.call str # This is synchronous!
end
end

return $?.success?
end
end

但是,没有任何输出出现,甚至不知道要正确执行单元测试。

Capistrano 可以工作,并且可以在 OSX 上工作。我的服务器是运行 Passenger 的 Ubuntu。

有人知道为什么输出不会被重定向吗?

谢谢

最佳答案

尝试在 cmd 上不使用 STDFDES 重定向这是我使用的和得到的。

class Executor
def execute_command(cmd, &block)
STDOUT.sync = true # That's all it takes...
IO.popen(cmd) do |pipe| # Redirection is performed using operators
pipe.sync = true
while str = pipe.gets
block.call str # This is synchronous!
end
end

return $?.success?
end
end

测试:

ex = Executor.new
ex.execute_command "ps aux" do |str|
p str
end

结果:

"USER PID %CPU %MEM VSZ RSS TT STAT STARTED
TIME COMMAND\n" "mitch 423 3.4 1.0 2750692 159552 ?? S 23Apr12 19:41.59 /Users/mitch/iTerm.app/Contents/MacOS/iTerm -psn_0_40970\n" "_windowserver 90 3.1 1.8 3395124 301576 ?? Ss 20Apr12 75:19.86 /System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.framework/Resources/WindowServer -daemon\n" "mitch 78896 2.0 0.8 1067248 136088 ?? R Thu03PM 37:46.59 /Applications/Spotify.app/Contents/MacOS/Spotify -psn_0_4900012\n" "mitch 436 1.8 1.0 1063952 169320 ?? S 23Apr12 100:23.87 /Applications/Skype.app/Contents/MacOS/Skype -psn_0_90134\n"

关于ruby-on-rails - Delayed_Job 执行 rake 不重定向输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4567896/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com