gpt4 book ai didi

java - 如何使用批处理脚本中的参数调用程序?

转载 作者:可可西里 更新时间:2023-11-01 09:48:16 26 4
gpt4 key购买 nike

我喜欢确定哪些 Java 运行时环境可用并检查它们的版本。我的代码将输出正确的 jre 路径,但无法执行 java.exe。

当程序路径是变量时,使用批处理脚本中的参数调用程序的正确方法是什么?

我的脚本

@echo off


:findjres
for /d %%i in ("C:\Program Files\Java\jre*") do (
set /a cpath+=1
call :pushpath "%%i"
)
for /d %%i in ("C:\Program Files (x86)\Java\jre*") do (
set /a cpath+=1
call :pushpath "%%i"
)
goto :versjres


:pushpath
set tpath=%1
set xpath!%cpath%=%tpath:~1,-1%
goto :end

:versjres
for /f "usebackq delims==! tokens=1-3" %%i IN (`set xpath`) do (
echo Array field number %%j have value %%k
%%k\bin\java.exe --version
)

pause


:end

错误

Exception in thread "main" java.lang.NoClassDefFoundError: Files
Caused by: java.lang.ClassNotFoundException: Files
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: Files. Program will exit.

最佳答案

换行

%%k\bin\java.exe --version

"%%k\bin\java.exe" -version

它对我有用。

关于java - 如何使用批处理脚本中的参数调用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12060432/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com