我正在尝试以 Java 进程的形式执行挂载命令。以下是我如何形成命令:
List<String> command = new ArrayList<String>();
command.add("cmd.exe");
command.add("/c");
command.add("mount.exe");
command.add("-u:" + username);
command.add("-p:" + password);
command.add(IP + ":" + mountPoint);
command.add(driveLetter + ":");
ProcessBuilder processBuilder = new ProcessBuilder(command);
processBuilder.redirectErrorStream(true);
Process process = processBuilder.start();
当我执行这个时,我得到的错误是,
'mount.exe' is not recognized as an internal or external command,
operable program or batch file.
我已经安装了mount.exe并且在环境变量中设置了路径,
C:\>where mount.exe
C:\Windows\System32\mount.exe
C:\>path
PATH=C:\Windows\System32;C:\Windows; ... [removed the remaining entries]
当我在命令提示符下手动执行命令时,它工作正常:
C:\>cmd.exe /c mount.exe -u:<user> -p:<password> <IP>:<mount point> Z:
如果有人能指出我遗漏的内容,我将不胜感激。
谢谢。
最佳答案
我在从 TeamCity Build Agent(作为服务工作,运行作为系统用户)。 当我通过单击 .cmd 文件从用户 session 运行脚本时脚本工作正常,但是当 TeamCity Build Agent 尝试运行它时,我看到完全相同的错误:
'C:\Windows\System32\umount.exe' is not recognized as an internal or external command
现在我有了解决方案。
mount 当您使用 C:\Windows\System32\cmd.exe 运行它时有效,因为cmd 搜索mount 在 C:\Windows\System32\
mount 当您使用 c:\Windows\SysWOW64\cmd.exe 运行它时 失败,因为此 cmd 搜索 挂载在c:\Windows\SysWOW64\
关于java - 从 Java 进程运行时找不到 mount.exe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15276071/