2014-11-01 1 views

답변

0
2.1.3 :005 > %x{(ls -d /boot 2>&1) | tee /dev/stderr} 
/boot 
=> "/boot\n" 

2.1.3 :006 > %x{(ls /no_such_file 2>&1) | tee /dev/stderr} 
ls: cannot access /no_such_file: No such file or directory 
=> "ls: cannot access /no_such_file: No such file or directory\n" 
1

리디렉션이 잘못되었습니다. 당신이 stderr

이 다시 stdout를 리디렉션 stderr 여기

1>&2stdout에 여기

2>&1 당신은 당신이 원하는 무엇인가 리디렉션 :

%x{command 2>&1}

하기에 puts를 호출해야합니다 스크립트에서 화면 출력을 얻으십시오. 이 도움이

puts %x{command 2>&1}

희망을 (모든 것을 대신 표준 오류의 현재 표준 출력하는 것입니다 때문에).

+0

Thx 그러나 원본 stderr과 stdout이 모두 캡처되어 화면에 표시되지 않습니다 (실시간). – Konstantin

+0

화면에 나타나지 않는다는 것은 무엇을 의미합니까? – ptierno

+0

스크립트에서 화면으로 출력하려면'puts '를 호출해야합니다. stderr이 화면에 간 유일한 이유는 오류이기 때문입니다. 'puts' – ptierno

관련 문제