954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

command line with C++

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

randomFIRE
Newbie Poster
12 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

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.

linux
Posting Shark
933 posts since Aug 2006
Reputation Points: 118
Solved Threads: 30
 

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

John A
Vampirical Lurker
Team Colleague
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
 

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.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

@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.

randomFIRE
Newbie Poster
12 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 

Thank you, I will try that out.


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

randomFIRE
Newbie Poster
12 posts since May 2007
Reputation Points: 10
Solved Threads: 0
 
edit: eh, sorry for double posting. Is there no way to delete posts on this forum?

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

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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.

balajisakhare
Newbie Poster
1 post since Jun 2010
Reputation Points: 9
Solved Threads: 0
 

yes this is possible.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You