prabodhprakash
prabodhprakash

Reputation: 3927

how to run a command

I want to run a command in Swift using Process. This is my current code:

process.launchPath = "/bin/sh"
process.arguments = ["symbolicatecrash", "crash.crash"]

However, this executes the command as sh symbolicatecrash crash.crash. I want this command to be executed as ./symbolicatecrash crash.crash. How can I achieve the same in Swift.

I tried the following code (which is a run time crash)

process.launchPath = ""
process.arguments = ["symbolicatecrash", "crash.crash"]

Upvotes: 1

Views: 114

Answers (1)

GhostCat
GhostCat

Reputation: 140447

Simple: when you want to be in full control of the path to be used - simply specify an absolute path for example, like:

process.arguments = ["/usr/bin/symbolicatecrash", "crash.crash"]

or where ever that script is located.

Beyond that: keep in mind that "./" as relative path depends on the context of your application.

In that sense: you could have a look here to understand how to actually "implement" relative paths - to then use that knowledge to create an absolute path that matches the desired relative path yourself.

But given the comment, the most "simple" answers seems to be:

process.launchPath = "usr/bin/env" process.arguments = ["./symbolicatecrash", "crash.crash"] i

Upvotes: 5

Related Questions