cocoa - Swift NStask function -
i'm complete swift noob. using code in xcode result need. created command line binary "menubar" takes several arguments. run in terminal "/bin/menubar getip", "/bin/menubar/getuser". want create function based on following working code.
import cocoa import foundation var task:nstask = nstask() var pipe:nspipe = nspipe() task.launchpath = "/bin/menubar" task.arguments = ["getip"] task.standardoutput = pipe task.launch() var handle = pipe.filehandleforreading var data = handle.readdatatoendoffile() var result_s = nsstring(data: data, encoding: nsutf8stringencoding) print(result_s)
i want convert function.
func commmand (argument: string) -> string { let task:nstask = nstask() let pipe:nspipe = nspipe() task.launchpath = "/bin/menubar" task.arguments = ["argument"] task.standardoutput = pipe task.launch() let handle = pipe.filehandleforreading let data = handle.readdatatoendoffile() let result_s = nsstring(data: data, encoding: nsutf8stringencoding) return result_s } commmand getip
try this:
func commmand(argument: string) -> string { let task:nstask = nstask() let pipe:nspipe = nspipe() task.launchpath = "/bin/menubar" task.arguments = [argument] task.standardoutput = pipe task.launch() let handle = pipe.filehandleforreading let data = handle.readdatatoendoffile() let result_s = string(data: data, encoding: nsutf8stringencoding)! return result_s } print(commmand("getip"))
Comments
Post a Comment