Page 1 of 1

Java Compiler Help Needed! (I'm using batch)

Posted: 24 Jul 2010 10:33
by sp11k3t3ht3rd
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?

Re: Java Compiler Help Needed! (I'm using batch)

Posted: 24 Jul 2010 12:08
by aGerman
Not sure if I understood what you want to do.

Code: Select all

if /i "%classname%"=="BeerSong" >"My.txt" type "%~0"

Regards
aGerman

Re: Java Compiler Help Needed! (I'm using batch)

Posted: 24 Jul 2010 12:26
by sp11k3t3ht3rd
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.

Re: Java Compiler Help Needed! (I'm using batch)

Posted: 24 Jul 2010 13:12
by aGerman
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

Re: Java Compiler Help Needed! (I'm using batch)

Posted: 24 Jul 2010 15:16
by sp11k3t3ht3rd
Thanks!

Re: Java Compiler Help Needed! (I'm using batch)

Posted: 24 Jul 2010 23:17
by sp11k3t3ht3rd

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...