How can I run an external program from C and parse its output?

后端 未结 8 967
死守一世寂寞
死守一世寂寞 2020-11-22 04:18

I\'ve got a utility that outputs a list of files required by a game. How can I run that utility within a C program and grab its output so I can act on it within the same pr

8条回答
  •  粉色の甜心
    2020-11-22 04:21

    For simple problems in Unix-ish environments try popen().

    From the man page:

    The popen() function opens a process by creating a pipe, forking and invoking the shell.

    If you use the read mode this is exactly what you asked for. I don't know if it is implemented in Windows.

    For more complicated problems you want to look up inter-process communication.

提交回复
热议问题