[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: running scripts



Junior <ejr@inbox.com> wrote:
> I'm hoping someone attempt this before. I can run a script from my C program
> but how do I get the script to return a variable or struct to the program?
> Has anyone done this before and can point me to an example?

When your C program starts a script, the script runs in a child process
which doesnt share memory with the parent process.

There are two easy ways to get information from the child back to the
parent (and many difficult ways).

The easiest way is if you just need to communicate an int, then you can
use the exit status of the child.

If you need more information you can use pipes.  The parent can then
read information (with scanf) that the child sends (with printf).
There's an example of this in the pipe(2) man page.


-- 
Sebastian Kuzminsky



Reply to: