Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Batch file...command output...ideas?
Closed Thread
Old 02-13-2007, 01:44 PM   #1 (permalink)
 
Monster Techie

Join Date: May 2004

Location: Tucson, AZ, USA

Posts: 1,183

Vormund

Send a message via AIM to Vormund Send a message via MSN to Vormund Send a message via Yahoo to Vormund
Question Batch file...command output...ideas?

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
__________________
Vormund is offline  
Old 02-13-2007, 02:37 PM   #2 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default

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.
jaeusm is offline  
Old 02-13-2007, 02:42 PM   #3 (permalink)
 
Monster Techie

Join Date: May 2004

Location: Tucson, AZ, USA

Posts: 1,183

Vormund

Send a message via AIM to Vormund Send a message via MSN to Vormund Send a message via Yahoo to Vormund
Default

Quote:
Originally 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.
Hah, that's perfect...and solves both issues!

Thanks, jaeusm!
__________________
Vormund is offline  
Old 02-13-2007, 02:51 PM   #4 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default

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.
jaeusm is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On