1

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?

3
  • 1
    Which os? What is buffer console output? What kind of buffer? etc Commented Nov 10, 2010 at 9:08
  • 1
    Related: stackoverflow.com/questions/2033878/… Commented Nov 10, 2010 at 9:15
  • Did you perhaps mean: "How to redirect the console output of another process to a buffer"? Commented Nov 10, 2010 at 9:51

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

It would be nice, if when someone downvotes, they leave a comment saying why. I'm here to learn as well.
Anonymous downvotes are one of my main dislikes about Stack Overflow. I think this info is relevant and accurate so +1
1

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.

1 Comment

thnx all for help, you give me exactly what I'm searching for :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.