EvilZone
Programming and Scripting => Scripting Languages => : chlortho June 24, 2015, 03:40:12 PM
-
Not sure if this belongs in Java or Scripting...
Anyhow, I am trying to write a script to compile and run simple java programs. Creating a batch file in DOS is a piece of cake:
javac %1.java
java %1
However, in BASH it's a bit more complicated (at least I think it is). Here is what I have so far, I feel like it's close. My issue (I think) is that there is not a -o switch with javac to specify the output file name. is there another way?
#!/bin/bash
# Script to compile and execute a jave program
# Get file name without the .java extension
file_name=$(echo $1|sed 's/\(.*\)\.java/\1/')
# Compile the program with -o option to specify the name of the binary
javac -o $file_name.out $1
# If there were no compilation errors, run the program
if [[ $? -eq 0 ]]; then
./$file_name.out
fi
-
1. this is obviously not python, but a shellscript.
2. get that ugly ass font from my screen.
3. haven't tested it, but it looks useful (kinda).
-
1. this is obviously not python, but a shellscript.
2. get that ugly ass font from my screen.
3. haven't tested it, but it looks useful (kinda).
1. right. I'm retarded. I was working on a python script to configure my network manager for my university wifi. Must have been thinking about two things at the same time.
2. Yeah. It looks like Courier... I cut and pasted from vim... so not really sure.
3. You're right, it's 'kinda' useful - more of just to see if I could.
Excellent feedback, though. Thanks.
-
I don't think so? Should be as simple as:
javac $1.java
java $1
Holy crap... That was it.... syntax %=CMD and $=Unix wow.... thanks! talk about over complicating things....haha
-
I don't think so? Should be as simple as:
javac $1.java
java $1
+1 said what I came here to say