How to output in buffer console output? For example I just need output of command "ipconfig -all", and want to store that information in some buffer?
-
1Which os? What is buffer console output? What kind of buffer? etcBЈовић– BЈовић2010-11-10 09:08:43 +00:00Commented Nov 10, 2010 at 9:08
-
1Related: stackoverflow.com/questions/2033878/…Adam Bowen– Adam Bowen2010-11-10 09:15:13 +00:00Commented Nov 10, 2010 at 9:15
-
Did you perhaps mean: "How to redirect the console output of another process to a buffer"?MSalters– MSalters2010-11-10 09:51:36 +00:00Commented Nov 10, 2010 at 9:51
2 Answers
You can write the output of a console application to a file (at least, in Windows), using the > parameter.
For example, for your case you'd write ipconfig -all > C:\output.txt to write the information to output.txt.
Alternatively, if you're doing it in code, you could create a process that runs ipconfig, and read the standard output using Microsoft's convoluted methods http://msdn.microsoft.com/en-us/library/ms682499%28VS.85%29.aspx, or an application framework such as Qt, which simplifies process management http://qt.nokia.com/products/ - see QProcess: http://doc.qt.nokia.com/4.3/qprocess.html#readAllStandardOutput
2 Comments
It seems you have an XY problem
What you really want to do is capture the output of another command. The whole "buffer" part is your first stab at an answer. It doesn't help you, and in fact it got you stuck thikning in the wrong direction.
badgerr offers some solutions, but the most common solution is popen("ifconfig -a", "r"). This doesn't return a buffer, it returns a FILE* that you can pass to fread. It's a POSIX function and available on Linux.
On Windows, you call CreateProcess and pass a STARTUPINFO structure containing dwFlags=STARTF_USESTDHANDLES, and hStdOutput=ResultOfCreatePipe.