Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 20th, 2008, 9:48 AM   #1
mikejones11234
Newbie
 
Join Date: Nov 2008
Posts: 21
Rep Power: 0 mikejones11234 is on a distinguished road
Copy batch file output to text file

I've created a batch file with the following code:

xcopy f:\ c:\backupFolder /E /S /I /Y

How do I code this batch file to show the DOS window copying all the files (which it does automatically) but also output that same list of files (exactly what it shows in the DOS window) to a text file in C:\backupFolder? I know how to redirect the output, but I want it to output to both places (screen and text file) without running the command twice. Thanks in advance!
mikejones11234 is offline   Reply With Quote
Old Dec 20th, 2008, 9:56 AM   #2
Fenrisulvur
Rather large Wolf
 
Fenrisulvur's Avatar
 
Join Date: Dec 2008
Location: Lyngvi >_>
Posts: 23
Rep Power: 0 Fenrisulvur is on a distinguished road
Send a message via MSN to Fenrisulvur
Re: Copy batch file output to text file

Maybe have it output to a buffer file, then print the contents of that file, before appending it to your record file? Though I guess you aren't immediately informed of progress if you use such means...
Fenrisulvur is offline   Reply With Quote
Old Dec 21st, 2008, 7:01 AM   #3
Jabo
Not a user?
 
Join Date: Sep 2007
Posts: 330
Rep Power: 3 Jabo is on a distinguished road
Re: Copy batch file output to text file

I haven't tested it, but I think all you need to do is to redirect your console output to a file like so:
/complete command/>>c:\backupfolder\xcopy.log

Give it a try and see if that works.
Jabo is offline   Reply With Quote
Old Dec 21st, 2008, 2:58 PM   #4
lectricpharaoh
SEXY SHOELESS GOD OF WAR!
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,676
Rep Power: 7 lectricpharaoh will become famous soon enough
Re: Copy batch file output to text file

@Jabo: that will preclude displaying the output to the screen (unless an error occurs, as that will probably go to stderr instead of stdout). The OP wants to do both, and besides the buffer to file, then echo said file, I can't think of any easy choices. I suppose you could write a program to pipe XCOPY's output to, and this program would read from stdin and write to both stdout and the file you specify, but that's probably overkill for this situation.
__________________
My microwave has settings for snake, gremlin, and puppy.
lectricpharaoh is offline   Reply With Quote
Old Dec 21st, 2008, 6:22 PM   #5
lectricpharaoh
SEXY SHOELESS GOD OF WAR!
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,676
Rep Power: 7 lectricpharaoh will become famous soon enough
Re: Copy batch file output to text file

For the curious:
C Syntax (Toggle Plain Text)
  1. /*
  2. ** pipeEcho.c
  3. **
  4. ** use to simultaneously echo the output of commands to
  5. ** stdout (ie, the console) and a supplied output file
  6. **
  7. ** syntax: command [arguments] | pipeEcho filename.ext
  8. */
  9.  
  10. #include <stdio.h>
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14. FILE *outFile = NULL;
  15. int ch;
  16.  
  17. if(argc > 1)
  18. {
  19. if(!(outFile = fopen(argv[1], "w")))
  20. puts("Unable to open specified output file; writing to stdout only.");
  21. }
  22. else
  23. puts("No output file specified; writing to stdout only.");
  24. while(EOF != (ch = getchar()))
  25. {
  26. if(outFile)
  27. fputc(ch, outFile);
  28. putchar(ch);
  29. }
  30. if(outFile)
  31. fclose(outFile);
  32. return 0;
  33. }
__________________
My microwave has settings for snake, gremlin, and puppy.
lectricpharaoh is offline   Reply With Quote
Old Dec 21st, 2008, 8:23 PM   #6
Ancient Dragon
PFO God In Training

 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 1,720
Rep Power: 7 Ancient Dragon will become famous soon enough
Re: Copy batch file output to text file

The unix tee command does just what you want. Here is a windows version. Its more than likely to be implementd similar to the previously posted program.
__________________
PFO's FAQ is here
Ancient Dragon is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch file problems bscr Other Scripting Languages 1 Jun 27th, 2008 10:08 AM
Help with fstream to a text file rhm54 C++ 6 Oct 22nd, 2007 9:39 PM
Dynamic form from text file. randum77 Visual Basic .NET 4 Apr 24th, 2007 11:39 AM
Adding more info to a text file without erasing crawforddavid2006 C# 2 Apr 11th, 2007 2:10 PM
Change the name of output file jazz C 4 Jun 28th, 2006 2:54 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:02 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC