Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
sp11k3t3ht3rd
- Posts: 26
- Joined: 20 May 2010 15:39
#1
Post
by sp11k3t3ht3rd » 24 Jul 2010 10:33
Okay I'm using a batch file to compile and run my java programs. This is the code:
Code: Select all
@echo off
title Mike Spallino's Java Compiler and Runner
:start
cls
echo.-----------
echo Options:
echo c - Compile
echo r - Run
echo.-----------
set /p input=Option:
if %input%==C goto compile
if %input%==c goto compile
if %input%==R goto run
if %input%==r goto run
:compile
cls
javac *java
pause
cls
goto start
:run
cls
set /p classname=Enter the class name:
pause
cls
java %classname%
pause
if %classname%==BeerSong
cls
set /p goback=Would you like to go back to the begining? (Y/N)
if %goback%==Y goto yes
if %goback%==y goto yes
if %goback%==N goto no
if %goback%==n goto no
pause
cls
echo That is not a valid command. You are now being disconnected.
pause >nul
exit
:yes
cls
pause
goto start
:no
cls
echo Thank you for using my compiler!
pause
exit
Where it says "if %classname%==BeerSong" which is a specific class I want this done for, I want the whole cmd to be placed into a text file. Is that possible?
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#2
Post
by aGerman » 24 Jul 2010 12:08
Not sure if I understood what you want to do.
Code: Select all
if /i "%classname%"=="BeerSong" >"My.txt" type "%~0"
Regards
aGerman
-
sp11k3t3ht3rd
- Posts: 26
- Joined: 20 May 2010 15:39
#3
Post
by sp11k3t3ht3rd » 24 Jul 2010 12:26
What I want to do is have everything that is run through the cmd to be copied and placed in a txt file. I want to do that because not everything in the class can be seen at runtime in the cmd because it has to many lines to print out. The Java program prints out the song
99 bottles of beer on the wall,
99 bottles of beer.
You take one down.
Pass it around.
98 bottles of beer on the wall,
98 bottles of beer.
You take one down.
Pass it around.
ect...
All the way down untill theres no more bottles but when I run the program It starts of with the bottom half of 60 bottles:
You take one down.
Pass it around.
And continues from there. I want to make sure the program is making all the lines so I want to have all the lines put into a .txt file. And that code didn't work aGerman.
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#4
Post
by aGerman » 24 Jul 2010 13:12
I'm not familar with Java, but as far I understand this line will return the output:
java %classname%In this case you should write
[...]
Code: Select all
:run
cls
set /p classname=Enter the class name:
cls
if /i "%classname%"=="BeerSong" (
>txt.txt 2>&1 java %classname%
) else (
java %classname%
)
pause
cls
[...]
Regards
aGerman
-
sp11k3t3ht3rd
- Posts: 26
- Joined: 20 May 2010 15:39
#6
Post
by sp11k3t3ht3rd » 24 Jul 2010 23:17
Code: Select all
:run
cls
set /p classname=Enter the class name:
cls
if /i "%classname%"=="BeerSong" (
>txt.txt 2>&1 java %classname%
) else (
java %classname%
)
pause
cls
Is there a way to change it so that it goes to a folder called bin to get the %classname%
For example:
My folder "Java" is located at C:\Java
The file is called boy.java and is located at C:\Java
When you compile the class file goes to a folder called bin which is located at C:\Java\bin
Is there anyway to get to that bin directory without having the specific location wrote out?
Something like "java \bin\%classpath%" even though I know that doesn't work I'm just trying to get my point across...