Tutorial :obtain output of command to parse in in c / MacOSX



Question:

I'm working on a Command Line app to help me on launchd tasks to know if a task is running by returning a BOOL, the problem comes when i need to do a command line and obtain the output for further parsing.

i'm coding it in C/C++ so i can't use NSTask for it, any ideas on how to achieve the goal?

The Command

sudo launchctl list -x [job_label]  

If i use system(), i'm unable to get the output so in further research I came with popen(), but no success there.

Thanks in advance.


Solution:1

You'll want to create a pipe from which you can read the output of the program. This will involve using pipe, fork, exec*, and maybe even dup. There's a good tutorial on the linux documentation project.


Solution:2

You can do it the home-brew way with pipe(), fork(), and the exec*() family of functions, or you could use popen() if its constraints meet your requirements.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »