Results 1 to 10 of 10
  1. #1
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Richmond, Virginia, USA
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating a log file from a batch file (XP Pro SP1)

    Is it possible to create a log file from a batch file? The next question would be an obvious "How?" Basically, I have a batch file that is manually run by a user (the file kills a bunch of tasks). I would like for the results of that file to be logged somehow so I can see what's going on after the fact (are all of the processes that are being killed actually still running when the batch file is run). I have no idea how to make it log, and my attempts so far have been very sad, indeed.

    Becky

    Funny - the lounge spell checker doesn't recognize the word "log" but it's fine with "logged"

  2. #2
    Plutonium Lounger
    Join Date
    Oct 2001
    Location
    Lexington, Kentucky, USA
    Posts
    12,107
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Creating a log file from a batch file (XP Pro

    I don't know what your batch file is doing, but the usual method of "writing" a file from a batch file is the redirection symbol ( > ). In running a command that normally produces on-screen results, to redirect that output to a file you might use: thecommand > c:somefoldersomefile.txt to write a file of what would normally appear on screen. Am I in your ballpark or not?

  3. #3
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Richmond, Virginia, USA
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating a log file from a batch file (XP Pro

    Yes! Thank you!! <img src=/S/fanfare.gif border=0 alt=fanfare width=31 height=23> That gave me almost exactly what I wanted. The only problem is that I would like for the stuff in the batch file to append the log (I have five lines and had to create five log files for this to work). Not a huge problem, but if there's an easy answer, I'd love to hear it. Here's basically what my batch file does:

    taskkill /f /im outlook.exe
    taskkill /f /im winword.exe

    There are more processes that it will kill, but that's the basic idea (this is to troubleshoot an issue with our Document Management System - it's not closing down everything the way it should, so we're trying to make sure it does).

    Thanks,
    Becky

  4. #4
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating a log file from a batch file (XP Pro

    Use >> instead of >. For example:

    ECHO Put this at the end of the file>>MYLOG.LOG

    Will add the text to the end of the file.
    Legare Coleman

  5. #5
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Richmond, Virginia, USA
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating a log file from a batch file (XP Pro

    Absolutely fabulous. The tech support guy I was talking to said that it was not possible to log the results of a batch file to a log file. I KNEW it could be done (I've seen it before), but I've never had to do it myself.

    Thanks so much to both of you!!
    Becky

  6. #6
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Creating a log file from a batch file (XP Pro

    Becky (oops! edited to give correct person!)

    Sack your Tech Support guy and get me to do your BATch files!

    John

    (I'll need a job in October!)
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  7. #7
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Richmond, Virginia, USA
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating a log file from a batch file (XP Pro

    Thanks, but I WOULD be the tech support person who writes the BATch files. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> No stealing my job!! <img src=/S/scold.gif border=0 alt=scold width=50 height=15> My boss, the sys admin, has delegated that job to me. Now that I've been writing them, I know at least as much as he does (at least about BATch files, anyway). Since I've never had any formal training on BATch files (or any programming type thing, for that matter), I have to learn what I need either by Googling or by asking questions here. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>

    Thanks anyway!

  8. #8
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Creating a log file from a batch file (XP Pro

    Becky

    Shall I say a little bit more about BATch files?

    There are two console output "streams", one for 'normal' messages (STDOUT, stream 1) and one for 'error' messages (STDERR, stream 2), although it's up to the programmer which s/he uses for what messages.

    You can direct the two streams to different files (either the output of a single command, or of the entire BATch file), as in

    MYBATCH 1>>STDOUT.LOG 2>>STDERR.LOG

    or to the same file (this syntax is correct, but by no means obvious)

    MYBATCH 1>>STDBOTH.TXT 2>>&1

    In both cases you could leave out the '1' in front of the '>>', and would usually do so except to make the redirection more obvious. Also, it would probably work (in this instance) if you replaced the '>>' by a single '>'. It's not common to direct all the output from a BATch file to a log file, but it's occasionally useful. More usually you want to collect the console output (if any) from one or more programs, so you would use something like

    PROGRAM1 > OURLOG.TXT

    to create a new log file, and

    PROGRAM2 >> OURLOG.TXT

    to add any console output from the second program to the same file. Note that I have left out the '1' and am letting any error messages written to STDERR to just appear on the screen.

    Hope that's not too unintelligible?

    John

    PS Invoice follows!!
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  9. #9
    4 Star Lounger
    Join Date
    Jan 2001
    Location
    Richmond, Virginia, USA
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Creating a log file from a batch file (XP Pro

    Not unintelligible. Just a smidge over my head. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> I may be able to make some sense of it if I play around with a few batch files for a bit. You still can't have my job, though! <img src=/S/razz.gif border=0 alt=razz width=25 height=17>

    Thanks!
    Becky

  10. #10
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Creating a log file from a batch file (XP Pro

    Grrrh!

    John
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •