System function, output to file

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2006
Posts: 11
Reputation: balgarath is an unknown quantity at this point 
Solved Threads: 0
balgarath balgarath is offline Offline
Newbie Poster

System function, output to file

 
0
  #1
Nov 18th, 2006
(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
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 223
Reputation: Anonymusius is on a distinguished road 
Solved Threads: 10
Anonymusius's Avatar
Anonymusius Anonymusius is offline Offline
Posting Whiz in Training

Re: System function, output to file

 
0
  #2
Nov 18th, 2006
If I correctly understand what you say would that be:
  1. int temp = system("last");
  2. mystream << temp;
  3. cout << temp;
Last edited by Anonymusius; Nov 18th, 2006 at 3:19 am. Reason: BBcode
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,662
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1502
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: System function, output to file

 
0
  #3
Nov 18th, 2006
do it just like you would from the command line.
  1. system("dir > myfile.txt");
Last edited by Ancient Dragon; Nov 18th, 2006 at 8:55 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 11
Reputation: balgarath is an unknown quantity at this point 
Solved Threads: 0
balgarath balgarath is offline Offline
Newbie Poster

Re: System function, output to file

 
0
  #4
Nov 18th, 2006
Thanks that got it. I didn't know that one but I do now. Appreciate the help.


Originally Posted by Ancient Dragon View Post
do it just like you would from the command line.
  1. system("dir > myfile.txt");
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 4388 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC