[英]How to use Java to start a bat file on windows and sh file on linux to run from a specific directory
I am trying to make a program which will execute a bat file when run on windows and a sh file when run on linux, but I need the bash/sh file to start running from a specific directory. 我正在尝试制作一个程序,该程序在Windows上运行时将执行bat文件,而在Linux上运行时将执行sh文件,但是我需要bash / sh文件才能从特定目录开始运行。
For example: My program is located at C:\\Program\\test.jar
My bash file is located at C:\\File\\start.bat
I want to make the java runnable execute the start.bat
file from its folder and not test.jar
running directory. 例如:我的程序位于
C:\\Program\\test.jar
我的bash文件位于C:\\File\\start.bat
我想要使Java可运行程序从其文件夹中执行start.bat
文件,而不进行test.jar
运行目录。
I tried using Runtime.getRuntime().exec("cmd /C start \\"\\" \\"C:\\File\\start.bat"");
我尝试使用
Runtime.getRuntime().exec("cmd /C start \\"\\" \\"C:\\File\\start.bat"");
and it works, but it runs the bat file from C:\\Program\\test.jar
, and for what the bat file does, I need it to run from C:\\File\\start.bat
. 它可以工作,但是它从
C:\\Program\\test.jar
运行bat文件,对于bat文件的功能,我需要它从C:\\File\\start.bat
。
I also need to do the same for Linux, so I am asking here because after the bat issue is fixed, this issue will likely stomp me as well. 对于Linux,我也需要做同样的事情,所以我在这里问,因为在解决bat问题之后,这个问题也可能使我感到困惑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.