2

I have a shell script program which gives some output. I need the output from the script and store in the c program.

lixiaomeng
  • 23
  • 3

1 Answers1

2

Theres two ways you can do this:

  1. Run the program from within the C program, using something like this: How to execute a command and get output of command within C++ using POSIX? The answer is written for C++ but it's all the same calls as in C.

  2. Pipe the output of the other program into your C program. This means your C program won't be executed before the other program though. For example, the command:

    ls | myprog

will take the output of "ls" and feed it into myprog, which can read it via scanf or fgets, for example.

Community
  • 1
  • 1
Verdagon
  • 2,456
  • 3
  • 22
  • 36