0

I have this shell command that return xml data. I'm new to Objective-C. I want to load in some XML using the system() function.

Can anyone help me or point me in the right direction?

Thanks in advance.

nikora
  • 817
  • 1
  • 14
  • 29
  • http://stackoverflow.com/questions/1475182/cocoa-objective-c-shell-command-line-execution – thelaws Nov 11 '12 at 18:11
  • I know how to run the command. I just need to get the returned value and be able to use it in a Objective-C application I'm making – nikora Nov 11 '12 at 18:47

1 Answers1

0

You can't use system() for that, because it doesn't return any data from the command to you. Instead, all of the program's output will go to the terminal.

The Cocoa way to do this is NSTask.

You need to:

  • use setLaunchPath and optionally setArguments to specify what program to run
  • pass an NSPipe to setStandardOutput
  • launch the program
  • read from the pipe until you hit the end of the input
Jamey Sharp
  • 8,363
  • 2
  • 29
  • 42