How do I get the PTY.spawn child exit code?

后端 未结 3 1022
清酒与你
清酒与你 2021-02-10 02:27

I\'m trying to manage a SSH connection to a network device via the PTY module, with a code similar to this:

cmd_line = \"ssh coltrane@love.supreme.com\"
begin
          


        
3条回答
  •  一整个雨季
    2021-02-10 03:01

    Ok, here are some possible solutions for this problem :

    • use ruby 1.9.2 PTY.check() method

    • wrap the command line in a script

    Unfortunately I can't use the latest version of ruby as so I used the wrapper solution, that echoes $? to a file at the end of the wrapper script. The exit code is read when the spawned child exits.

    Of course if something interrupts the execution of the wrapper script itself, then we'll never get the result file ...

    But at least this workaround can be used for 1.8.7/1.9.1 versions of Ruby

提交回复
热议问题