Reputation: 47
I am writing Server-Client program Java.
To test this program, I need to run several cmd windows. And this is very boring, especially if you just start work. The program operates in three sub-programs:
So I would like to write a script (I don't know how to do it because I've never written anything in batch) that:
launches one cmd window in the directory e.g. E:\java\myapp\
-will call the command: java -cp (myJAR) app.Server
will run two cmd windows in: E:\java\myapp\
-call the command: java -cp (myJAR) app.Node
and finally launch one client window: E:\java\myapp\
-call the command: java -cp (myJAR) app.Client
Upvotes: 0
Views: 134
Reputation: 38622
I would recommend using the Start
command, as advised in the comments:
@Start "Customer" /D "E:\Java\MyApp" Cmd /K "java -cp (myJAR) app.Client"
@Start "Employee" /D "E:\Java\MyApp" Cmd /K "java -cp (myJAR) app.Node"
@Start "Server" /D "E:\Java\MyApp" Cmd /K "java -cp (myJAR) app.Server"
You could also, if the working directory is the same for each use this alternative:
@PushD "E:\Java\MyApp" 2>NUL && (
Start "Customer" Cmd /K "java -cp (myJAR) app.Client"
Start "Employee" Cmd /K "java -cp (myJAR) app.Node"
Start "Server" Cmd /K "java -cp (myJAR) app.Server"
PopD)
Or this:
@CD /D "E:\Java\MyApp" 2>NUL || Exit /B
@Start "Customer" Cmd /K "java -cp (myJAR) app.Client"
@Start "Employee" Cmd /K "java -cp (myJAR) app.Node"
@Start "Server" Cmd /K "java -cp (myJAR) app.Server"
Another alternative, if the intention is to ensure that the ClassPath search includes E:\Java\MyApp
or E:\Java\MyApp\myJAR.jar
is to add it directly to the commands:
@Start "Customer" Cmd /K "java -cp E:\Java\MyApp\myJAR.jar app.Client"
@Start "Employee" Cmd /K "java -cp E:\Java\MyApp\myJAR.jar app.Node"
@Start "Server" Cmd /K "java -cp E:\Java\MyApp\myJAR.jar app.Server"
As also advised in the comments, to read the help and usage information for the Start
and Cmd
commands, open a Command Prompt window and enter start /?
and cmd /?
respectively.
Upvotes: 1
Reputation: 15488
Use this:
@Echo Off
cmd /k "pushd E:\Java\MyApp & java -cp (myJAR) app.Server"
cmd /k "pushd E:\Java\MyApp & java -cp (myJAR) app.Node"
cmd /k "pushd E:\Java\MyApp & java -cp (myJAR) app.Client"
Upvotes: 1