I have a shell script program which gives some output. I need the output from the script and store in the c program.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.