Hi, I'm trying to use command line stuff with C++. I've read that you do it with System(); Is that the best way?

My main question however, is how do you read in the results from the command? I think I can do 'thecommand > file' to output the results to a file, and then read from the file with C++, but I want to know if there is a easier way I can get the results directly without going through that middle file.

Thanks

Recommended Answers

All 8 Replies

What do you mean by "command line stuff"? This is very vague. System() can be used to control your program, yes, using commands like "PAUSE" and "CLS," however I would suggest using something like cin.get() or cin.ignore() over System("PAUSE").

Be more specific please.

Oh, and it's system(), not System().

you can use popen to create a pipe between your program and the other executable. Output of that other program will can be read by your program via the pipe.

@joeprogrammer
oops, you're right. lowercase.

@linux
Sorry for being vauge. By "command line stuff" i mean, "command line commands", but I since you have been able to learn a (possibly multiple) programming language, then you would understand what I meant.

My question obviously wasn't about pause or cls though, because I asked about how I can read in the output from the command (e.g. from netstat) . Since pause and cls don't give any output, I wasn't talking about them.

Thank you, I will try that out.


edit: eh, sorry for double posting. Is there no way to delete posts on this forum?

edit: eh, sorry for double posting. Is there no way to delete posts on this forum?

Yes, ask and thy wish might be granted.:)

Hi,i want to know the idea for developing a command prompt based line editor. so using this utility & its predefined command user will be able to open,delete,close,swap lines in the file.

commented: Start your own thread, don't bump an old one -1
Member Avatar for iamthwee

yes this is possible.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.