我有一个从java执行的bat文件,并将输出结果保存在java变量中。脚本从cmd运行时运行良好,也从java执行,我在java中得到了exit值,但无法得到返回值。下面是我正在使用的java代码和bat脚本。
java代码
String filePath = "1234";
StringBuilder scriptOutputResult = new StringBuilder();
Process process = Runtime.getRuntime().exec(new String[]{"cmd.exe", "/c", "start C:\\Thread\\Value\\xyz.bat", filePath});
exitCode = process.waitFor();
log.info("Command returned exit code = {}", exitCode);
try (BufferedReader stdInput = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
log.info("Reading the output of shell script");
String line = null;
while ((line = stdInput.readLine()) != null) {
scriptOutputResult.append(line).append("\n");
}
log.info("Output from the script executed is :{}", scriptOutputResult.toString());
}
输出.log
Command returned exit code = 0
Output from the script executed is :
xyz.bat公司
@ECHO OFF
SET filePath=%1
ECHO %filePath%
IF "%filePath%" == "" (
ECHO Missing File Path
EXIT /B 1
GOTO :eof
) ELSE (
ECHO %filePath%
EXIT /B 0
GOTO :eof
)
请让我知道,如果我在批处理文件或任何其他方式,以获得文件的输出在java中以其他方式丢失的东西。
暂无答案!
目前还没有任何答案,快来回答吧!