2011-12-30 2 views
0

시스템 명령으로 실행되는 명령이 있습니다. 쉘에 전달 된 내용을 기록 할 수 있습니까?Ruby 및 시스템 입력

P. 난 당신이 시스템 명령

command = "whoami" # store the command as string 
puts command  # print it before you execute it 
system(command)  # execute it in the shell 
+0

"무엇이 통과 되었습니까?" 시스템 커멘드가 돌려주는 결과 – Vapire

+0

쉘에서 호출 할 정확한 문자열 –

+0

명령의 출력을 캡처 하시겠습니까? –

답변

1

당신은 "따옴표의 문제"를 가지고 언급로 전송되기 전에 당신은 단순히 문자열을 인쇄 할 수 있습니다

1

qoutes의 =의 문제)를 가지고있다. 큰 따옴표라고 생각 하나? Vapire의 솔루션을 다음으로 수정하십시오.

command = %Q{echo "double quoted string"} # store the command as string 
puts command        # print it before you execute it 
system(command)       # execute it in the shell 
관련 문제