Running a Terminal Command from my MacOS App

can someone tell me how to run a terminal command from within my program? something like if i put this in the terminal " exiftool -b -ThumbnailImage -Orientation=1 test.cr2 > thumbnail2.jpg "

Replies

Use NSTask.

Example please.

NSTask is deprecated use

'Process()'

and

'Pipe()'

Yes, deprecated in Swift.


In objC, NSTask still valid.

Example please. Preferably with the command I pasted.

Are you kidding ?


Members of this forum are not your subordinates who execute your orders.


If you want exmple, you may search yourself.

I cannot find one. That's why I asked.

Here's what I have so far..


         let params = ["/users/monicakachlon/documents/facedetect-master/face_detect_cv3.py", "test.cr2"]
          let task = Process.launchedProcess(launchPath: "python", arguments: params)



I get the error:



[General] launch path not accessible

Ok. I'm getting there



 
let paths = path! + "/" + item let thumbnailPath = "thumbnailTwo.jpg"
let taskTwo = Process.launchedProcess(launchPath: "/usr/local/bin/exiftool", arguments: ["-b","-ThumbnailImage", paths, thumbnailPath])

This is an attempt at doing this: exiftool -b -ThumbnailImage test.cr2 > thumbnailTwo.jpg I don't know how to add the ">"

If you want to redirect the standard output to file, you need to create an instance with `Process()`, set the properties of the instance appropriately, including the property `standardOutput`. And then launch it.