objective c - NSTask vs System - pros and cons? -
i'm @ point in project need call system commands. started looking @ nstask (as seems popular approach) came across system command. looks far easier setup nstask. i've seen questions/answers nstask better approach, don't see
- what advantages/disadvantages between 2
- in cases 1 more used other
any help/links/thoughts/ideas? (and yes.. did google search)
nstask:
- can run task in background. allows send interrupts , kills underlying process, , allows suspend or resume underlying process without setting threads yourself. can run synchronously if that's want.
- let's work , forth cocoa classes,
nsstrings without having buncha conversions. - let's set i/o streams underlying process differ caller's.
- better supported across apple platforms (like ios)
system(3)-- don't thinksystemworks on ios. - requires cocoa , objective-c.
- doesn't interpret shell arguments or path expansions of arguments.
system(3):
- better supported across unix-like platforms.
- can run task one-liner.
- only requires c.
- runs in shell , interpret working directory , arguments
/bin/shwould.
for cocoa app use nstask; use system if i'm doing must c-only or know have run under non-mac environments. is, system pretty brittle , more robust solution doing fork-exec, because allows more control on streams , concurrent operation.
Comments
Post a Comment