The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Program Output
Discuss Program Output in the C Programming forum on Dev Shed. Program Output C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

February 27th, 2003, 08:49 AM
|
|
Contributing User
|
|
Join Date: Dec 2002
Location: Memphis, TN
Posts: 199
Time spent in forums: 2 h 45 m 7 sec
Reputation Power: 11
|
|
|
Program Output
Is there a way to store my output into a file, so that I can look over it later yet still see the output on the screen as I'm running the program?
|

February 27th, 2003, 09:19 AM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
|
If you're running this on a *nix system, then the easiest way would be to simply pipe your output through the tee command. man tee for more info.
|

February 27th, 2003, 09:21 AM
|
|
Contributing User
|
|
Join Date: Dec 2002
Location: Memphis, TN
Posts: 199
Time spent in forums: 2 h 45 m 7 sec
Reputation Power: 11
|
|
|
I'm runng it on a compiler I have on the system. Anyone know of a C++ compller that does this internally or automaticlly?
|

February 27th, 2003, 10:04 AM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
Quote: Originally posted by Sonic98
I'm runng it on a compiler I have on the system. Anyone know of a C++ compller that does this internally or automaticlly? |
What comes immeditately to mind is to use pairs of print commands: one to the screen and the other to a file. This might be streamlined a bit if you were to use sprintf() to create the output string and the print the string to both destinations; eg:
Code:
sprintf(s,"%d,%d,%d\n",x,y,z);
write(stdout,s,strlen(s));
write(fd,s,strlen(s));
Or using the higher-level printf() and fprintf() functions.
You didn't say whether you are using a UNIX/Linux system or DOS, nor which compiler you are using. That would give us a better idea of what tools or techniques would be available to you.
|

February 27th, 2003, 12:00 PM
|
|
Contributing User
|
|
Join Date: Dec 2002
Location: Memphis, TN
Posts: 199
Time spent in forums: 2 h 45 m 7 sec
Reputation Power: 11
|
|
|
I'm am compiling locally on a Windows XP. I am using the Dev C++ compiler from Bloodshed. It compiles the program then runs the exe at the command prompt. IS there another compiler with a better executing/debugging method out there?
|

February 27th, 2003, 03:44 PM
|
|
Contributing User
|
|
Join Date: Feb 2003
Posts: 138
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
Not sure what your doing exectly but this may help.
compile.bat
Code:
dir drive: 2>a.txt 1>b.txt
type a.txt
This code fails because drive: is not valid so std error will output as dir normally has no output for a valid call.
stderr ie filehandle 2 will be redirected to the file a.txt and stdout ie filehandle 1 will be redirected to b.txt
You can then just type the output of the file to the screen!
__________________
--
ngibsonau
|

February 27th, 2003, 04:43 PM
|
|
Contributing User
|
|
Join Date: Dec 2002
Location: Memphis, TN
Posts: 199
Time spent in forums: 2 h 45 m 7 sec
Reputation Power: 11
|
|
|
....
Last edited by Sonic98 : February 27th, 2003 at 04:45 PM.
|

February 27th, 2003, 04:46 PM
|
|
Contributing User
|
|
Join Date: Dec 2002
Location: Memphis, TN
Posts: 199
Time spent in forums: 2 h 45 m 7 sec
Reputation Power: 11
|
|
Quote: Originally posted by ngibsonau
Not sure what your doing exectly but this may help.
compile.bat
Code:
dir drive: 2>a.txt 1>b.txt
type a.txt
This code fails because drive: is not valid so std error will output as dir normally has no output for a valid call.
stderr ie filehandle 2 will be redirected to the file a.txt and stdout ie filehandle 1 will be redirected to b.txt
You can then just type the output of the file to the screen! |
The program I am using is a C++ editor and compiler. When I tell it to compile a program, it creates an exe if there is no error. Then win you click debug, it runs the exe. The way it runs the exe is no different than going to the command/dos prompt and running the exe. In other words it runs it in a DOS window. The only way I've been able to print the out is to do a file.exe>file.txt. But if I do it this way, I don't see the output on the screen, but everything does show up in the text file.
|

February 27th, 2003, 06:04 PM
|
|
Contributing User
|
|
Join Date: Feb 2003
Posts: 138
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
|
As long as you don't have a long running compile and you don't care if you don't see all the errors in real time just use a batch file that has "type file.txt" after the line that compiles.
As long as your OS allows redirection of stderror also you should have no problems. (But you've already though of that?)
I think MS DOS 5 and 6 you can anly redirect stdout. But NT and 2000 seem to redirect stderr fine.
|

February 28th, 2003, 01:54 AM
|
|
Contributing User
|
|
Join Date: Dec 2002
Location: Memphis, TN
Posts: 199
Time spent in forums: 2 h 45 m 7 sec
Reputation Power: 11
|
|
|
Nevermind. I forgot that this is WinXP. I can copy and paste from cmd prompt.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|