我如何运行在运行一个.jar第二.bat文件来执行命令.bat文件? [英] How do I run a .bat file for commands to execute in a second .bat file running a .jar?

查看:348
本文介绍了我如何运行在运行一个.jar第二.bat文件来执行命令.bat文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨社区,我需要知道我怎么可以运行.bat文件到一个文本字符串eacute到一个.bat文件运行的.jar使用的命令。

Hey community I need to know how I can run .bat file to eacute a string of text to a .bat file running a .jar to use the command.

也批处理文件来运行其他批处理文件命令将被从Windows任务计划程序运行。

also the batch file to run the command in the other batch file will be run from Windows Task Scheduler.

这是用于通过的方式的Minecraft服务器。总之下面是code用于运行批处理文件中的.jar。命令语法就是停止

This is for a Minecraft server by the way. anyhow below is the code used to run the .jar in the batch file. the command syntax is just "stop".

server.bat code

java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui.


因此​​,长期来看,我需要做所谓的批处理文件的 stop.bat且可以从Windows中运行的任务计划程序即可。在 stop.bat且文件,我需要在文件中exacute命令在 server.bat 文件,以便服务器将停止,在那之后我可以只运行在 server.bat 以重新启动服务器。


So in long terms I need to make a batch file called stop.bat to be run from Windows Task Scheduler. In the stop.bat file I need the file to exacute the command in the server.bat file so that the server will stop, after that I can just run the server.bat to start the server again.

如何可以做到这一点有什么想法?
基本奠定了这一切应该如何工作如下。

any thoughts on how this can be done? basic lay out how this should all work is below.

服务器的run.bat >>>奔跑>>>我的世界 - 的server.jar

server-run.bat >>> "Runs" >>> minecraft-server.jar

任务计划程序>>>奔跑>>> stop.bat且

Task Scheduler >>> "Runs" >>> stop.bat

>>> stop.bat且在执行命令>>>服务器的run.bat

stop.bat >>> "Executes command in" >>> server-run.bat

推荐答案

假设你的服务器run.bat文件看起来是这样的:

assuming your server-run.bat file looks something like this:

@echo off
:startserver
java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui.
:running

pause
REM or whatever you do normally to stop the server
:stopserver
java stop
REM or whatever the command to stop the server is
exit

有关文件,以便能够跳到由acalling批处理文件定义了一些标记,你应该将其更改为:

for the file to be able to jump to some mark defined by acalling batch file, you should change it to:

@echo off
if "%*" NEQ "" goto %*
:startserver
java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui.
:running

pause
REM or whatever you do normally to stop the server
:stopserver
java stop
REM or whatever the command to stop the server is
exit

和stop.bat且应该aproximately是这样的:

and stop.bat should look aproximately like this:

@echo off
start server-run.bat stopserver

remem ^ BER这是直接从运行的stop.bat服务器停止命令的另一种方式。如果这是行不通的(东阳它需要一个环境在变什么的)这种做法也将失败!

remem^ber this is just another way of running the server-stop-command directly from stop.bat. if that wouldn't work (beacause it needs an environnement variable or something) this approach will also fail!

(这是东阳你不能直接与正在运行的批处理文件或它的变量干扰,你只能在同一时间运行的副本)

(this is beacause you can't directly interfere with a running batch file or its variables, you can only run a copy of it at the same time)

如果您wnat与正在运行的批处理文件来干扰,最简单的方法是定期检查文件是否存在:

if you wnat to interfere with a running batch file, the easiest way would be to check periodically if a file exists:

@echo off
:startserver
if exists stopfile.txt del stopfile.txt
java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui.
:running

if exists stopfile.txt goto stopserver
timeout /T 2
goto running 


:stopserver
del stopfile.txt
java stop
REM or whatever the commabd to stop the server is
goto :EOF
exit

和stop.bat且只是做到这一点:

and stop.bat just does this:

@echo off
echo.something >stopfile.txt
exit

这将导致服务器running.bat到

this will cause the server-running.bat to

-run服务器

- 检查每2秒,如果stopfile.txt apperared

-check every 2 seconds if stopfile.txt apperared

- 如果它做,停止服务器

-if it did, stop the server

(记得更改与Java code中的虚拟线,
我不知道,如果他们是正确的)

(remember to change the dummy lines with the java code, i have no idea if they are right)

希望这有助于到底

这篇关于我如何运行在运行一个.jar第二.bat文件来执行命令.bat文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆