我正在编写一个 bat 脚本,在其中调用一个程序(例如 javac)。为简单起见,我想在运行之前检查该命令是否存在。即如果命令存在于 PATH 中。
例如,
if (my_command.exe is a recognized command) then (
my_command.exe my_args
) else (
REM Output was probably "'my_command.exe' is not recognized as an internal or external command, operable program or batch file."
REM Do not run my_command.exe
)
Run Code Online (Sandbox Code Playgroud)
在 Windows 中执行此操作的最佳方法是什么?