JohnSundell / ShellOut

Easily run shell commands from a Swift script or command line tool
MIT License
872 stars 85 forks source link

Don't close standard file handlers #23

Closed SteveBarnegren closed 4 years ago

SteveBarnegren commented 6 years ago

When 'shelling out' to an async operation, FileHandler.standardOutput can be passed in to see the output in realtime, in the same way as if the command had been executed in the Terminal:

try shellOut(to: "pod repo update", outputHandle: FileHandle.standardOutput)

ShellOut currently calls closeFile() on the passed in output handler and error handler. In the case that one of the 'standard' handlers has been passed in, this causes issues such as print() not working.

This PR checks for the 3 standard handlers (input, output, error) and bypasses the call to closeFile(). Any other passed in FileHandler will receive the call.

@JohnSundell let me know how you feel about this solution. It does add a special casing for the 3 handlers (which is a bit weird), but the advantage is that there's no additional complexity to the api, which is probably a good thing for a scripting library!

SteveBarnegren commented 4 years ago

Hey @JohnSundell. No problem, it's nice to finally get it merged in! 👍