2014-04-14 1 views
0

net-ssh 수동 서적에서 "exec"메소드가 채널에서 명령을 비동기 적으로 실행한다고합니다. http://net-ssh.github.io/ssh/v1/chapter-3.html#s6Ruby net ssh 채널을 사용하여 강사를 순서대로 실행하려면 어떻게해야합니까?

하지만, 예를 들어, 위해 일부 강사를 실행할 수 있도록 노력하겠습니다 때

def work(session, instructor) 
    session.open_channel do |channel| 
    channel.on_data do |ch, data| 
     puts data.strip 
    end 
    channel.exec instructor 
    end 
end 

Net::SSH.start('host') do |session| 
    work session, "touch a.file" 
    work session, "mv a.file b.file" 
    work session, "rm b.file" 
    session.loop 
end 

명령을 실행 비동기 정말 작동하지 않는 등의 코드를합니다.

아무도 나를이 문제를 해결하는 데 도움이 될 수 있습니까?

감사합니다.

답변

1

그것을 위해 사용 sync shell service 수행과 같은 :

Net::SSH.start('localhost') do |session| 
    shell = session.shell.sync 
    shell.touch 'a.file' 
    shell.mv 'a.file', 'b.file' 
    shell.send_command("rm", 'b.file') 
    shell.exit 
end 

하거나 명령을 구성 온 - 라인 :

work session, "touch a.file; mv a.file b.file; rm b.file" 
+0

내가 간부 인 할 명령은 기본 쉘이 아닌 경우 명령? 제 생각에는 괜찮습니다. 그러나 내 명령이 매우 길면 분명하지 않다. 감사. – wonderflow

+0

@wonderflow 문서는 쉘이 bash 일 뿐이라고 말하지 않는다. –

+0

@ МалъСкрылевъ - SSH 연결 상태에 약간의 문제가 있습니다. 도와주세요 - https://stackoverflow.com/questions/28799593/unix-commands-work-on-server-but-not-in-ruby-ssh-session 감사합니다. – james

관련 문제