0

I am using the solution described in here to call a command line tool from within my Swift app, but always receive an error for the file I am giving as an argument. If I just copy the complete call string to Terminal, it runs just fine.

My first thought was that it might has to do with the spaces in the file path, but that does not matter. Since the response comes from the tool itself, not from shell, the call seems to be OK in general. The path that I am using as an argument comes from a file dragged into the app from the finder.

Call from Swift:

self.shell("/Applications/AtomicParsley","'\(FileURLLabel.stringValue)'","--artwork REMOVE_ALL --overWrite")

Response in console:

AP error trying to fopen '/Users/Tom/Downloads/Test file.m4v': No such file or directory
AtomicParsley error: can't open '/Users/Tom/Downloads/Test file.m4v' for reading: No such file or directory
Community
  • 1
  • 1
Tom G.
  • 1
  • 2
  • Can you try creating the command strings into a variable and print that variable using `print` and see what it prints? You can try using double quotes instead of single quotes for enclosing the filename? – Pradeep K Feb 18 '16 at 08:32
  • Guesswork and vague ideas here but...maybe just passing a stringValue isn't good enough? Perhaps you could try to create a NSURL from your string value, maybe even `let url = NSURL(fileURLWithPath: FileURLLabel.stringValue)`. And then use the `absoluteString` or `path` of your new `url` object. (you can read more about the differences here: http://stackoverflow.com/questions/16176911/nsurl-path-vs-absolutestring). Hope this makes sense and doesn't lead you in the wrong direction – pbodsk Feb 18 '16 at 08:48

1 Answers1

0

Thanks, pbodsk, using path of NSURL was the solution. Besides, I had to use string constants rather than just the literals for the other parameters as well when calling the shell. Thanks alot!

Tom G.
  • 1
  • 2