Running a script in system() call and want the script's output

Hi All,

I have a script(sample.sh) displaying the output of "dd" command. Now i am using this script in system() call as,

system("sh sample.sh") in an application file.

I want the output of system("sh sample.sh") in the application file itself.

How can i get it?

Many thnaks.
amio

In what programming language is your application written?

Maybe redirect the system() execution output to a file?

Something like this:

system("sh sample.sh 1>sample.out 2>sample.err")

And then do what you need in the sample[out|err] files.

You can parse the full output to a file with the > after the sh file.sh, if you want this...

It should already be outputting to the same terminal as your application. Where else do you want it?

in the application file itself.....Ammm
sh sample.sh > sample.sh ???? This will overwrite the executable with the output, don't do it if you're not sure that this is the correct solution

I think he wants something like, in Perl and Shell:

variable=`/path/to/sample.sh`

But if we don't know what programming language the application is written, it is difficult.

Assuming you are programming in C, don't use system() but popen() to get the command output.

The application is written in C. As of now, am redirecting the output to a file and reading it from the file.

Thanks a lot for everyone's inputs..

In C you can use popen() as jlliagre mentioned.

Regards