简体   繁体   中英

Application, Helper Tool Communication

I'm working on a OS X desktop application. I want to bundle a helper tool with it. I was thinking of using SMJobSubmit to start a helper program with elevated privileges. (The tool basically does a sudo call.)

How could I send the console output from the tool back to my main application?

I know with NSTask I could use NSPipe to redirect console output. But, since I don't think I can use NSTask with elevated privileges, I'm using SMJobSubmit instead.

(Yes, I've taken care of the authorization part.)

I think, as far as I know, you should use XPC connection to communicate with your helper program. Instead of using SMJobSubmit(Since it is deprecated anyway) use SMJobBless to install your helper tool as a LaunchD job which runs in elevated privileges. Use XPC connection from your Mac OS X app to communicate with it to invoke the function call that executes your logic, capture the output and reply back to the main app. If you are willing to go ahead with this idea, the below sample code from Apple will guide you through.

https://developer.apple.com/library/mac/samplecode/EvenBetterAuthorizationSample/Listings/Read_Me_About_EvenBetterAuthorizationSample_txt.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM