Wrapper for NIOSSHClient (swift nio ssh client example)

I'm reopening this very old thread because I ran into the same issue. I am using this code as a base for my own app. The example app is intended to be run from command-line and it performs the specified action and exits. If you want to utilize this code to run SSH commands multiple times from a single process, then yes it hangs on the second iteration on:

try childChannel.closeFuture.wait()

There is a good clue in this thread Add SSH support to NIO project.

The ExampleExecHandler.channelActive() has a line that uses stdout and stdin file handles directly.

}.takingOwnershipOfDescriptors(input: 0, output: 1).whenComplete { result in

The solution is to dup() those file handles so that the duplicates are closed instead of the originals. Like so:

}.takingOwnershipOfDescriptors(input: dup(0), output: dup(1)).whenComplete { result in
1 Like