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

System function, output to file

(c++)
Ok so I understand how to use the system function, and how to output to a file. How do I pipe the output of say system("last") to a file?
system() returns an int, so if I mystream << system("last") it will put an int in the file. I need to intercept the output going to the screen(cout?) and put it in the file (mystream? or can I do this in the last command with some parameters?)

Thanks

balgarath
Newbie Poster
11 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

If I correctly understand what you say would that be:

int temp = system("last");
mystream << temp;
cout << temp;
Anonymusius
Posting Whiz in Training
238 posts since Aug 2006
Reputation Points: 129
Solved Threads: 11
 

do it just like you would from the command line.

system("dir > myfile.txt");
Ancient Dragon
Retired & Loving It
Team Colleague
30,046 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,342
 

Thanks that got it. I didn't know that one but I do now. Appreciate the help.

do it just like you would from the command line.

system("dir > myfile.txt");
balgarath
Newbie Poster
11 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You