Thread: Program Output

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Memphis, TN
    Posts
    199
    Rep Power
    12

    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?
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
    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.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Memphis, TN
    Posts
    199
    Rep Power
    12
    I'm runng it on a compiler I have on the system. Anyone know of a C++ compller that does this internally or automaticlly?
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,145
    Rep Power
    2222
    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.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Memphis, TN
    Posts
    199
    Rep Power
    12
    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?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    138
    Rep Power
    12
    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
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Memphis, TN
    Posts
    199
    Rep Power
    12
    ....
    Last edited by Sonic98; February 27th, 2003 at 04:45 PM.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Memphis, TN
    Posts
    199
    Rep Power
    12
    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.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    138
    Rep Power
    12
    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.
    --

    ngibsonau
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Memphis, TN
    Posts
    199
    Rep Power
    12
    Nevermind. I forgot that this is WinXP. I can copy and paste from cmd prompt.

IMN logo majestic logo threadwatch logo seochat tools logo