Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 在cmd上运行jar文件的批处理文件_Batch File_Cmd - Fatal编程技术网

Batch file 在cmd上运行jar文件的批处理文件

Batch file 在cmd上运行jar文件的批处理文件,batch-file,cmd,Batch File,Cmd,抱歉,如果重复,我想从命令提示符运行一个jar文件,因此我可以创建一个批处理文件,而不是转到特定路径, 只需双击批处理文件即可完成我的任务, 我在[1]中发现了一些东西,但在我的例子中它不起作用,我想运行java-jar squirrelsql.jar 我想制作一个批处理文件,该文件: 1) 打开cmd.exe 2) 在该命令提示符中运行桌面上的java-jar squirrel sql.jar 3) 使窗口保持打开状态,以便在需要时可以运行其他命令 我如何才能做到这一点?将以下内容保存为squ

抱歉,如果重复,我想从命令提示符运行一个jar文件,因此我可以创建一个批处理文件,而不是转到特定路径, 只需双击批处理文件即可完成我的任务, 我在[1]中发现了一些东西,但在我的例子中它不起作用,我想运行
java-jar squirrelsql.jar

我想制作一个批处理文件,该文件:

1) 打开cmd.exe

2) 在该命令提示符中运行桌面上的
java-jar squirrel sql.jar

3) 使窗口保持打开状态,以便在需要时可以运行其他命令
我如何才能做到这一点?

将以下内容保存为squirrel.bat

java -jar squirrel-sql.jar

REM /P causes SET to prompt and wait for Enter.
REM The underscore is used to ensure that "sure" is not already
REM an environment variable.
set /p _sure="Do you want to exit? [press Enter]"

REM /I causes a case-insensitive comparison
if /I NOT "_sure"=="y" (
  REM /B exits the batch script but not the CMD window
  exit /b
) else (
  REM Any other modifications
)

尝试
start cmd/k java-jar squirrel sql.jar
@nouseforname:非常感谢。使用此代码并保存.bat文件扩展名,然后双击将运行的bat文件欢迎使用Stackoverflow!即使您的答案可能是有效的,它也不会为任何未来有相同问题的用户提供信息。请您在回答中详细说明您的代码的作用以及它如何解决问题?这用于运行jar并执行不同的操作,而不关闭cmd。如果用户希望退出jar而不是cmd,请按照用户的意愿执行。