943,945 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 5813
  • C++ RSS
Nov 18th, 2006
0

System function, output to file

Expand Post »
(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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
balgarath is offline Offline
11 posts
since Oct 2006
Nov 18th, 2006
0

Re: System function, output to file

If I correctly understand what you say would that be:
C++ Syntax (Toggle Plain Text)
  1. int temp = system("last");
  2. mystream << temp;
  3. cout << temp;
Last edited by Anonymusius; Nov 18th, 2006 at 3:19 am. Reason: BBcode
Reputation Points: 129
Solved Threads: 11
Posting Whiz in Training
Anonymusius is offline Offline
223 posts
since Aug 2006
Nov 18th, 2006
0

Re: System function, output to file

do it just like you would from the command line.
C++ Syntax (Toggle Plain Text)
  1. system("dir > myfile.txt");
Last edited by Ancient Dragon; Nov 18th, 2006 at 8:55 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Nov 18th, 2006
0

Re: System function, output to file

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.
C++ Syntax (Toggle Plain Text)
  1. system("dir > myfile.txt");
Reputation Points: 10
Solved Threads: 0
Newbie Poster
balgarath is offline Offline
11 posts
since Oct 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Array problem
Next Thread in C++ Forum Timeline: problem with "for" statement





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC