I have a shell script program which gives some output. I need the output from the script and store in the c program.
-
How do you intend to "store a value in a program"?user529758– user5297582013-01-14 07:06:41 +00:00Commented Jan 14, 2013 at 7:06
-
I want to get some strings from some text files with awk.And,store the strings in virables of C program.lixiaomeng– lixiaomeng2013-01-14 07:10:53 +00:00Commented Jan 14, 2013 at 7:10
Add a comment
|
1 Answer
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.
1 Comment
Grijesh Chauhan
Good!! : @OP below I implementation of 2 option