Sha256: faf48c459051002cde8c90c173c5c82602c0654ceb14928901602f015e643928

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

The SyncShell service allows you to execute commands on the shell and block until they finish. It is not fool-proof--it has to use some tricks to accomplish this task, and some commands may foul it up. But for most tasks, it works admirably.

[!figure lang=ruby,number=true,caption=Using the SyncShell service
Net::SSH.start( 'localhost' ) do |session|

  shell = session.shell.sync

  out = shell.pwd
  p out.stdout

  out = shell.test "-e foo"
  p out.status

  out = shell.cd "/really/bogus/directory"
  p out.stderr
  p out.status

  out = shell.ruby "-v"
  p out.stdout

  out = shell.cd "/usr/lib"

  out = shell.ls "-l"
  p out.stdout

  out = shell.send_command( "bc", <<CMD )
5+5
10*2
scale=5
3/4
quit
CMD
  p out.stdout

  p shell.exit

end
!]

The result of executing each command is an object that encapsulates the @stdout@ and @stderr@ streams, and the exit status of the command.

To explicitly execute a command, use the @#send_command@ instead of @#send_data@--otherwise, the command will be executed asynchronously, which is not what you want. Also, if you pass a second parameter to the @#send_command@ method, it is interpreted as the @stdin@ data to send to the new process.

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
net-ssh-0.9.0 doc/manual/parts/shells_sync.txt
net-ssh-1.0.0 doc/manual/parts/shells_sync.txt