[Batch file...command output...ideas?] - Computers



Search Tech-Forums - link takes you to our Forum's search page.

Note: The following is only a text archive!


To view the actual forum discussion, please visit our website at http://www.tech-forums.net

Pages:1



Batch file...command output...ideas?

(Click here to view the original thread with full colors/images)



Posted by: Vormund

I'm trying to make a simple batch file for compiling Java files via the command line, for the time being to do this:

1. Run the batch.
myBatchFile.bat MyClass

2. Compile the file.
javac %1.java

3. Determine if an error was spewed by Java, if so, abort, otherwise continue.
This is where the problem is - how to determine if Java spewed an error.

I was thinking along the lines of running the compile command with the > file.txt, and determining if file.txt had content, if so, there was an error...but that doesn't work, it only creates an empty file (which I don't fully understand as of yet).

As well, I still want the error displayed on the screen, so even if it did work, I want the error displayed as well.

4. Run the class
java %1


The bottom line, does anyone have any idea how to do #3? If you need clarification, let me know...

TIA!
Vormund



Posted by: jaeusm

You could take a slightly different approach. Instead of trying to redirect the compiler output to file, just check to see if a .class file exists. Of course, this method would require you to first check the directory for an existing .class file and delete it before calling javac.exe.



Posted by: Vormund

[QUOTE][i]Originally posted by jaeusm [/i]
[B]You could take a slightly different approach. Instead of trying to redirect the compiler output to file, just check to see if a .class file exists. Of course, this method would require you to first check the directory for an existing .class file and delete it before calling javac.exe. [/B][/QUOTE]

Hah, that's perfect...and solves both issues!

Thanks, jaeusm!



Posted by: jaeusm

You're welcome. A better solution might be to use the return code from javac.exe. However, I don't know how to obtain the code for use in a batch file. You'd have to do some research for that.





vBulletin Copyright ©2000 - 2003, Jelsoft Enterprises Limited.


PPC Management
vB Easy Archive Final - Created by Xenon