Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mount.exe not found when run from a Java Process

I'm trying to execute a mount command as a Java Process. 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,

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.

like image 598
Yam Avatar asked May 14 '26 09:05

Yam


1 Answers

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). 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:

'C:\Windows\System32\umount.exe' is not recognized as an internal or external command

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\

mount fails when you run it with c:\Windows\SysWOW64\cmd.exe, because this cmd searches for mount in c:\Windows\SysWOW64\

like image 165
Dmitry Borisov Avatar answered May 15 '26 23:05

Dmitry Borisov