简体   繁体   English

从Java进程运行时找不到mount.exe

[英]mount.exe not found when run from a Java Process

I'm trying to execute a mount command as a Java Process. 我正在尝试将mount命令作为Java进程执行。 The following is how I form the command: 以下是我如何构成命令:

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();

When I execute this, I get the error that, 当我执行此操作时,我收到错误,

'mount.exe' is not recognized as an internal or external command,
operable program or batch file.

I've mount.exe installed and the path is set in the environment variable, 我安装了mount.exe,并在环境变量中设置了路径,

C:\>where mount.exe
C:\Windows\System32\mount.exe

C:\>path
PATH=C:\Windows\System32;C:\Windows; ... [removed the remaining entries]

When I execute the command manually at the command prompt, it works fine: 当我在命令提示符下手动执行命令时,它工作正常:

C:\>cmd.exe /c mount.exe -u:<user> -p:<password> <IP>:<mount point> Z:

I would be grateful if someone can point out what I'm missing. 如果有人能指出我所缺少的东西,我将不胜感激。

Thanks. 谢谢。

I have the same problem with running mount and unmount on Windows Server 2008 x64 from TeamCity Build Agent (works as a service, runs as System user). 从TeamCity Build Agent在Windows Server 2008 x64上运行mountunmount时遇到同样的问题(作为服务运行,以System用户身份运行)。 Script works fine when I run it from user session by clicking the .cmd file, but when TeamCity Build Agent tries to run it, I see the very same error: 当我通过单击.cmd文件从用户会话运行脚本时脚本工作正常,但是当TeamCity Build Agent尝试运行它时,我看到了同样的错误:

'C:\\Windows\\System32\\umount.exe' is not recognized as an internal or external command “C:\\ Windows \\ System32 \\ umount.exe”未被识别为内部或外部命令

Now I have the solution. 现在我有了解决方案。

mount works when you run it with C:\\Windows\\System32\\cmd.exe, because cmd searches for mount in C:\\Windows\\System32\\ 使用C:\\ Windows \\ System32 \\ cmd.exe运行它时, 挂载 工作 ,因为cmd在C:\\ Windows \\ System32 \\中搜索mount

mount fails when you run it with c:\\Windows\\SysWOW64\\cmd.exe, because this cmd searches for mount in c:\\Windows\\SysWOW64\\ 当您使用C运行安装 失败 :\\ WINDOWS \\ Syswow64资料\\ cmd.exe的,因为这种安装 CMD搜索在C:\\ WINDOWS \\ Syswow64资料\\

See what happens when you write the full path for mount.exe in your command.add() calls. 看看在command.add()调用中编写mount.exe的完整路径时会发生什么。 I may be wrong about this, but I think that when you call cmd.exe from within a command prompt yourself, the environment variables are passed automatically to the called program. 我可能错了,但我认为当你自己在命令提示符中调用cmd.exe时,环境变量会自动传递给被调用的程序。 This may not be happening correctly using ProcessBuilder, and if the full path works, it might be an indication of that. 使用ProcessBuilder可能无法正确执行此操作,如果完整路径有效,则可能表明这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM