Windows:
batfilePath=this.getClass().getResource("/do.bat").getPath().replaceAll("%20", " ").substring(1).replace("/", "\\");
ps = Runtime.getRuntime().exec("cmd /C start /b "+batfilePath+"");
Linux/Unix:
batfilePath=this.getClass().getResource("/do.sh").getPath().replaceAll("%20", " ").replace("\\", "/");
ps = Runtime.getRuntime().exec("sh "+batfilePath);
本文介绍了如何在Windows和Linux/Unix系统中使用Java代码来启动不同类型的批处理文件(.bat/.sh)。通过修改路径并利用Runtime.getRuntime().exec()方法,可以实现跨平台执行批处理脚本。
329

被折叠的 条评论
为什么被折叠?



