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

  1. what advantages/disadvantages between 2
  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 think system works 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/sh would.

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

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -