• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 714
  • Last Modified:

MS Dos batch file log and append to file

I have a batch file that runs fine.

How can I run this with logging to file on the second command only?

This works fine when I run it
I just want to log results of the executeable to a txt file

@echo off
cd "c:\program files (x86)\Java\jre7\bin"

java -cp m5.jar;m5-data-objects.jar;webservices-rt.jar;log4j-1.2.13.jar org.m5.sdk.hostedconnect.v2.MonitorMultipleExample
0
lrbrister
Asked:
lrbrister
  • 2
  • 2
2 Solutions
 
MisbahCommented:
add this to the end of your command line :  > log.txt

java -cp m5.jar;m5-data-objects.jar;webservices-rt.jar;log4j-1.2.13.jar org.m5.sdk.hostedconnect.v2.MonitorMultipleExample > log.txt
0
 
oBdACommented:
You just redirect the output with ">SomeFile" (will erase an existing file before writing) or ">>SomeFile" (will add to an existing file):
@echo off
cd "c:\program files (x86)\Java\jre7\bin"

java -cp m5.jar;m5-data-objects.jar;webservices-rt.jar;log4j-1.2.13.jar org.m5.sdk.hostedconnect.v2.MonitorMultipleExample >"C:\The\file.log" 2>&1

Open in new window

The "2>&1" redirects stdout (where most program write their error output) to the file, too.
0
 
lrbristerAuthor Commented:
Thanks guys.
Watch for follow-up
0
 
oBdACommented:
Just noticed an error: the last line in my previous post should of course have been 'The "2>&1" redirects stderr (where most program write their error output) to the file, too."
0
 
lrbristerAuthor Commented:
oBdA
I saw that and modified it.  No worries
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now