how to run a console and store its output?

Aug 29, 2011 at 3:24pm
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 Aug 29, 2011 at 3:25pm
Aug 29, 2011 at 3:35pm
popen is what you need and it exists not only on Linux.
Aug 29, 2011 at 3:56pm
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 Aug 29, 2011 at 4:02pm
Aug 29, 2011 at 4:29pm
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?
Aug 29, 2011 at 4:35pm
Search MSDN for its entry (inc example code)

==> http://msdn.microsoft.com
Aug 29, 2011 at 4:39pm
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 Aug 29, 2011 at 5:02pm
Aug 30, 2011 at 12:08am
???

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