GeekyOmega GeekyOmega - 6 months ago 18
Perl Question

Inquiry: How to convert this batch file to shell script?

I was given a batch file called make.bat with the following information:

javac Node.java
javac PhysServer.java
start java Physerver topology.txt 8080
start java Node A localhost 8080
start java Node B localhost 8080


Since I run OSX and linux, I cannot run batch files. Hence, how could I rewrite
this as a perl script and run in terminal? I tried the following below but it crashes:

#!/user/bin/perl
javac Node.java
javac PhysServer.java
start java Physerver topology.txt 8080
start java Node A localhost 8080
start java Node B localhost 8080


The error I get is:

Number found where operator expected at ./make2.pl line 5, near "txt 8080"
(Do you need to predeclare txt?)


I also suspect that I should delete "start" in front of java and just invoke the java command. I am sorry about this silly question, but I am rusty with scripts in general and have been teaching myself how to write perl and makefiles lately to start saving time.

Also, when I have been searching for an answer, I mostly found posts talking about how to run perl in java, which is something I don't want to do. I thought that was something I could do with perl, but comments below corrected me. I'm learning and won't make the same mistake ever again. Thanks for all your posts. I will vote and comment on all.

Answer

Perl is a complete programming language like Java. It's not the best choice for this. A bourne shell script would be easier:

#!/bin/sh
javac Node.java
javac PhysServer.java
java Physerver topology.txt 8080 &
java Node A localhost 8080 &
java Node B localhost 8080 &

If you want to add error checking,

#!/bin/sh
javac Node.java &&
javac PhysServer.java && (
   java Physerver topology.txt 8080 &
   java Node A localhost 8080 &
   java Node B localhost 8080 &
)

In a comment, you indicated you want to start each server in a new Window. I'm not an OS X user, so I had to look it up. Another answer suggests

#!/bin/sh
pwd="`pwd`"

javac Node.java &&
javac PhysServer.java && (
   osascript -e "tell application \"Terminal\" to do script \"cd \\\"$pwd\\\"; clear; java Physerver topology.txt 8080\"" >/dev/null
   osascript -e "tell application \"Terminal\" to do script \"cd \\\"$pwd\\\"; clear; java Node A localhost 8080\"" >/dev/null
   osascript -e "tell application \"Terminal\" to do script \"cd \\\"$pwd\\\"; clear; java Node B localhost 8080\"" >/dev/null
)
Comments