如何在 Windows 命令提示符后台运行 Java 应用程序?

huangapple 未分类评论52阅读模式
英文:

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

huangapple
  • 本文由 发表于 2020年4月9日 14:02:27
  • 转载请务必保留本文链接:https://java.coder-hub.com/61114870.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定