2

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

2
  • How do you intend to "store a value in a program"? Commented 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. Commented Jan 14, 2013 at 7:10

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Good!! : @OP below I implementation of 2 option

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.