Open Frizlab opened 4 years ago
Yes this is something that should be better supported in SwiftShell. It might be better to have all the run*
-commands throw errors if they can't be executed.
For now you can verify the command is available first:
guard SwiftShell.run("which","wrongcommand").succeeded else {
// handle error
}
let c = runAsync("wrongcommand")
Or you can let bash handle it:
let c = runAsync(bash: "wrongcommand")
try c.finish()
Then the error will be thrown when you call finish()
.
Another workaround, I think, would be to call runAsync("/usr/bin/env", "wrongcommand")
. The wrongcommand
can even be a full path, it seems to work.
There are few OSes where /usr/bin/env
does not exist AFAICT.
Specifically I’m launching a process in a server (yes, I know, I shouldn’t!), and it’s a pity having a server being killed like that, even in the case of a misconfiguration.
I’ve seen the
launchThrowably()
method on theProcess
extension; I was thinking of something along these lines but forrunAsync
(e.g.runAsyncThrowably
?)