Help withcalling Windows *.exe programs that require a Windows account
I am trying to use robocopy.exe (basically a better version of xcopy) to copy files from \\serverA\sahrename to \\serverB\\sharename from serverC running the java program. Here is my code:
Process p = Runtime.getRuntime().exec("robocopy \\\\serverA\\sharename \\\\serverb\\sharename *.*");
This failes with an error code of 2(whatever that means). When I run the same command from the command line, it works fine.
robocpy.exe uses my login credentials to access the network share drives. The share drives are set up to give my user full access.
So the question is...
Can I run a Java program as a Windows user? I can't install my program as a Windows service because I need to run the program on demand, and not all the time.
Thanks!
[803 byte] By [
nweddlea] at [2007-11-27 0:17:01]

http://www.google.com/search?hl=en&q=windows+error+2
Windows Error 2 is: The system cannot find the file specified.Try specifying the absolute paths (start with the drive letter)
Thanks for the tips. I tried to use the drive letter as well, and got the same error. The error has nothing to do with the path. I know the path I am using is correct because it works when I run it from a DOS window.
The question is, how can I run a Java program under a Windows user? I am thinking this is not even possible. I think I need to use something other than robocopy.
Any ideas would be helpful. I need to be able to copy files from one remote server on demand to another in a Windows 2003 environment
> Thanks for the tips. I tried to use the drive letter
> as well, and got the same error. The error has
> nothing to do with the path. I know the path I am
> using is correct because it works when I run it from
> a DOS window.
But you're not specifying a path. So you don't know the path you're using is correct. So you should try using an absolute path.
Or you could ignore the advice offered on the grounds that you "know better" but then why are you bothering to ask in that case?
I thought it was pretty clear that I was specificying a path: \\serverA\sharename This is a share path in Windows, and they do not have drive letters. Don't confuse a mapped drive with a share drive. A mapped drive is accessed using a drive letter such as Y:\dirname whereas a share is access by \\servername\sharename
This is from the robocopy doc
Examples:
:: Copy files from one server to another
ROBOCOPY \\Server1\reports \\Server2\backup *.doc /S /NP
As you can see, the only path specified is a share path.
I did take the advice of the other posters, and reported that it made no difference with a drive letter, it still failed.
Yes, I do know that my path is correct, because , again, like I stated in my post, it works on the command line. The same exact command works on the command line.
dcminter, does have a high post count give one the right to make unhelpful comments? Also, read my post closer next time before responding.
Hey bozo, you're looking in the wrong place. The path in question is this one: "robocopy". Nothing to do with those UNC paths at all. Just specify the full path to robocopy, or specify its extension properly, or both. Runtime.exec() doesn't start an instance of the shell, so you can't compare its actions to what the shell does (like defaulting executables to .exe and so on). Claiming that it works at the command line means nothing.
If that was unhelpful, then that's too bad. Deal with it.
> dcminter, does have a high post count give one the
> right to make unhelpful comments?
No, but reading things like this does:
"I know the path I am using is correct because it works when I run it from a DOS window."
> Also, read my post
> closer next time before responding.
I did. You apparently didn't understand my reply, however.
DrClap,
Thanks for the response.
I thought everyone was referring to my share paths as being wrong, not the path to robocopy.
I was able to get this to work by doing the following:
String[] s = {"cmd.exe", "/c", "robocopy \\\\serverA\\shareName \\\\serverB\\shareName *.*"};
Runtime.getRuntime().exec(s);
This works too:
String s = "C:\\Program Files\\Windows Resource Kits\\Tools\\robocopy.exe \\\serverA\\shareName \\\\serverB\\shareName *.*"
Runtime.getRuntime().exec(s);
Despite calling me a Bozo, you get the points for helping me solve this. Thanks!
dcminter, in the future, don't jump on people who are trying to work through a problem. I don't think I know any better than anyone else, I just thought people were referring to my share paths and not the robocopy path. That does not deserve the response you gave. We don't want to create an environment on this board where people are affraid to post.
> We don't want to create an environment on this
> board where people are affraid to post.
Umm . . .yes we do, it the people posting don't read and try the replies. You're just wasting our time, if you don't.
Note that if you had done what I said in reply 2 you would have corrected the problem.
Message was edited by:
ChuckBing
> I just thought people were referring to my
> share paths and not the robocopy path.
And yet instead of saying that you thought your paths were correct, you said that you knew they were. And you're still trying to defend your position.
If you had been a little more humble, you might have said that you had tried it at the command prompt and that it had worked so you thought your paths must be ok. Instead you said you knew they were.
If you had instead adjusted your code as requested with your misapprehension intact, and posted it, I woudn't have jumped on you and your mistake would immediately have been apparent.
As it is, if I hadn't jumped on you, it's entirely possible that you would have provided no more information, received no further feedback, and still be stuck on this problem.