I've been trying for some days now to find and equivalent to Ruby's exec
in Swift.
I haven't yet been able to find a solution. Multiple sources online suggest how to forward predefined input to STDIN of the child process and out to read its output, but now how to start a child process and let it take control of the STDIN and STDOUT as if the Swift process was letting it take over.
The use case would be to run SSH commands and develop an in-house company tool, formerly in Ruby, that would allow similar features as heroku run /bin/sh
for instance. I am already able to replicate things like heroku logs
, since they donnot require user input.
The basic idea of starting a new process and attaching it to STDIN and STDOUT doesn't seem to be working as expected.
let task = Process()
task.launchPath = "/usr/bin/env"
task.arguments = ["bash", "-c", "read"]
task.standardInput = FileHandle.standardInput
task.standardOutput = FileHandle.standardOutput
task.standardError = FileHandle.standardError
task.launch()
task.waitUntilExit()
Any ideas or hints of how to achieve this ?