1

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"] 
1
  • More thanks ;-) and you could consider deleting the no longer required comments now. Have a great day. I hope to acquire the legendary badge today, and your 25 points make a good start into this day. Because of that, you also won in the GhostCat upvote lottery. Commented Sep 7, 2017 at 5:41

1 Answer 1

5

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 
Sign up to request clarification or add additional context in comments.

3 Comments

It does not answer my question of having an ability of running as, "./symbolicatecrash"
Please also see a related question: stackoverflow.com/questions/46068822/…
process.launchPath = "usr/bin/env" process.arguments = ["./symbolicatecrash", "crash.crash"] is the right way to run this. Since your answer closely matches, please update this, post which I can mark this as correct. It is important to do it this way because without providing launchPath, application would crash at run time.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.