2010-12-31 6 views
2

현재 지연된 작업을 통해 실행중인 클래스가 있습니다. 그 중 하나는 "rake spec"을 실행하고 출력을 재지향하는 것입니다.Delayed_Job 레이크를 실행하지 않고 출력을 리디렉션하지 않습니다.

나는 같은이 작업을 수행 :

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 

그러나, 출력 중 어느 것도 표시되지 않습니다 그것도 제대로 단위 테스트를 실행할 인식하지 않습니다.

카피 스트라 노가 작동하며 OSX에서 작동합니다. 내 서버는 우분투 승객입니다.

누구나 출력이 리디렉션되지 않는 이유는 무엇입니까? 여기에 cmd를 에 STDFDES 리디렉션없이

감사

답변

2

시도 내가 무엇을 얻을 내가 사용하는 것이다.

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 

결과 :

"미치 423 3.4 1.0 2,750,692"사용자 PID %의 CPU % MEM VSZ RSS TT STAT가
TIME COMMAND \ 없음 시작 " 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 /시스템/라이브러리/프레임 워크/응용 프로그램 서비스 프레임 워크/프레임 워크/코어 그래픽. 프레임 워크/리소스/Windows 서버 - 디몬 \ n ""mitch 78896 2.0 0.8 1067248 R Thu03PM 37 : 46.59/적용/Spotify.app/Contents/MacOS/Spotify -psn_0_4900012 \ n ""mitch 436 1.8 1.0 1063952 169320 ?? S 23Apr12 100 : 23.87 /신청/유형/콘텐츠/MacOS/글꼴 -psn_0_90134 \ n "

관련 문제