obtain output of command to parse in in c / MacOSX
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.
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.
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.
精彩评论