SwiftShell icon indicating copy to clipboard operation
SwiftShell copied to clipboard

Request for an API that do not exit when executable to run is not found

Open Frizlab opened this issue 5 years ago • 2 comments

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 the Process extension; I was thinking of something along these lines but for runAsync (e.g. runAsyncThrowably?)

Frizlab avatar Jul 17 '20 16:07 Frizlab

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().

kareman avatar Jul 18 '20 17:07 kareman

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.

Frizlab avatar Sep 23 '20 15:09 Frizlab