objective c - How should I go about creating a Cocoa application that outputs to the command-line? -
i'm attempting build cocoa application uses third-party cocoa api (it needs respond url-scheme). want application simple possible, , act "helper" application else.
it seems best way me have application launched command-line with arguments , write output, either directly cli or intermediary file such plist, before exiting.
how can best produce output (assuming dump command line), and/or there better way of going this?
general advice only, "best" subjective!
if producing multiple "blobs" (that's technical term ;-)) of output use c's standard i/o functions, if going output 1 blob can use write
. basic approach is:
- produce output
nsstring
- anyway like - use
utf8string
method ofnsstring
(or convert other character set encoding) produce c string - output c string
stdout
fputs
etc. or file descriptor1
usingwrite
if doing multiple times wrap above method takes format string/arguments needed etc.
you'll see cli applications produce output terminal in plist format, can useful applications helpers - calling application can read output via pipe , convert plist dictionary/array reading .plist file. more direct approach writing plist file , reading back.
but helpers don't need have cli or gui, can launch , communicate them various forms of ipc. if app sandboxed xpc helpers should considered.
hth
Comments
Post a Comment