how to run a console and store its output?

Like in the title, i need a function which will run a specific program (In this case its a console) and i will be able to store its output in a variable. I'm looking for function like exec in PHP.

@edit: I have searched google for about 2 hours, and everything didn't work or was only for linux.
Last edited on
popen is what you need and it exists not only on Linux.
or was only for linux.

So you're using Windows?

If so, and you're using Visual Studio, the function Athar mentioned has acquired an underscore prefix: _popen

store its output in a variable.

What kind of variable do you mean?

_popen returns a stream (FILE*) -- associated with one end of a pipe -- which allows you to capture the progam's output. It's up to you to process this output so it can be stored in one or more variables.

(On Windows, you can do the same kind of thing with CreateProcess and CreatePipe, but it is rather more involved)
Last edited on
yes im Using Visual Studio and Windows. I was using popen and it didnt work, Looks like _popen is working, can u give me any documention regarding this function?
Search MSDN for its entry (inc example code)

==> http://msdn.microsoft.com
Ok thx, once i know what function to use, i think im gonna be ok :P

Now what command should i use to run a program ? I have all the code from microsoft.com but dont know the command.
Last edited on
???

_popen is the command to run a program and get the output!
Topic archived. No new replies allowed.