英文:
How to run java application in Windows command prompt background?
问题
以下是等效的Windows批处理/cmd脚本:
@echo off
java -classpath "thirdparty1.jar;thirdparty1.jar" com.myapp.Main
exit 0
请注意,Windows批处理脚本不需要使用&
来在后台运行进程,因为Windows的命令行界面允许你在同一个终端中运行多个实例。至于传递参数,你可以像下面这样在Windows批处理脚本中使用它们:
@echo off
java -classpath "thirdparty1.jar;thirdparty1.jar" com.myapp.Main %1 %2
exit 0
在这个脚本中,%1
代表第一个参数(例如,100),%2
代表第二个参数(例如,test)。
你可以像下面这样运行多个实例:
> app-launcher.bat 100 test
> app-launcher.bat 200 test
> app-launcher.bat 200 test1
英文:
We have a java application and written a shell script to launch this application in Linux.
Same way we written a batch file in Windows.We want to execute multiple instance of this application so we are using & in Linux shell script to execute the java process in background. Then your can use the same terminal to launch one more application and so on. We want to achieve the same in Windows. We also need to pass parameters to this launcher script.
Below is the launcher script for Linux , we need the equivalent Windows batch/cmd script.
The requirement is , user should be able to launch multiple times from the same terminal as like below.
Note: It will be good, if have simple solution in batch/cmd file not interested in power shell.
> app-launcher.sh 100 test
> app-launcher.sh 200 test
> app-launcher.sh 200 test1
#!/bin/sh
java -classpath "thirdparty1.jar":"thirdparty1.jar" com.myapp.Main &
sleep 2 &&
exit 0
专注分享java语言的经验与见解,让所有开发者获益!
评论