Command does not return results in SWIFT

222 views Asked by At

I'm trying to run a command line tool and taking the result. I checked it in terminal:

/usr/bin/exiftool -filename -directory -createdate -model "/Users/dirk/Desktop\" -t -S -q -r -f >"RenamerOutfile0.txt"

This runs fine and delivers result in file. Using SWIFT I tried this:

let task = NSTask()
task.launchPath = "/usr/bin/exiftool"
task.arguments = ["-filename -directory -createdate -model \"/Users/dirk/Desktop\" -t -S -q -r -f"]
let pipe = NSPipe()
task.standardOutput = pipe
task.launch()

let data = pipe.fileHandleForReading.readDataToEndOfFile()

Unfortunatly nothing happens. data is assigned 0 byte - no result. If I insert the redirection to file no file is created. Any idea what's the difference in calling the tool from terminal than with this task?

1

There are 1 answers

0
Peter71 On

I found a workaround:

let x = system("/usr/bin/exiftool -filename -directory -createdate -model \"/Users/dirk/Desktop\" -t -S -q -r -f >\"/var/tmp/RenamerOutfile0.txt\"")

This works fine. Maybe because I added the path /var/tmp for output file? Doesn't matter! :-)