Spool an interactive JAVA program ?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
skt1977
Posts: 2
Joined: 17 Sep 2011 09:09

Spool an interactive JAVA program ?

#1 Post by skt1977 » 17 Sep 2011 09:17

I run an interactive JAVA program on the DOS prompt and want to be able to save the whole interaction in a txt file.

Is there a way to achieve it ?

I run a batch file like this

C:\> runbatch.bat

which contains the following command

C:\> Java ABC

This program will ask some questions from the user then do some processing. How to I spool everything from from the java programs output ?

All help is appreciated.

regards
SKT

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Spool an interactive JAVA program ?

#2 Post by dbenham » 17 Sep 2011 20:03

Major Edit: OOPS! I missed the key word interactive. My "solution" below in black will not work since you won't be able to see or respond to the prompts.

You need something like the Unix tee command - it sends stdout to the console and to a file.

I have a version of tee for Windows, but I don't remember where it came from. Search the internet for free unix utilities for Windows.

----------------
To simply capture stdout into a file use:

Code: Select all

Java ABC >test.txt
This will overwrite any existing test.txt file

If you want to preserve the existing test.txt and append the results to it, then use:

Code: Select all

Java ABC >>test.txt

Note that the above only captures stdout, not stderr. Error messages will not be captured if they are written to stderr.

If you want to capture both stdout and stderr:

Code: Select all

Java ABC >test.txt 2>&1

or using append

Code: Select all

Java ABC >>test.txt 2>&1


Dave Benham

skt1977
Posts: 2
Joined: 17 Sep 2011 09:09

Re: Spool an interactive JAVA program ?

#3 Post by skt1977 » 18 Sep 2011 22:54

thanks dave, I did download one tee utility but that hangs. i think i will search more until i find one.

regards
skt

Post Reply