I have a shell script program which gives some output. I need the output from the script and store in the c program.
Asked
Active
Viewed 569 times
2
-
How do you intend to "store a value in a program"? – Jan 14 '13 at 07:06
-
I want to get some strings from some text files with awk.And,store the strings in virables of C program. – lixiaomeng Jan 14 '13 at 07:10
1 Answers
2
Theres two ways you can do this:
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.
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.