• Post Reply Bookmark Topic Watch Topic
  • New Topic

Works through command line but not getRuntime.exec()  RSS feed

 
C La
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am passing this as my command line string into getRuntime.exec(). It should change directory to C:\MyBuildDir and then run the perl script there which copies some files around among other things.

When I run it through exec I can see it switches the dir and runs the file because I can see that the perl script is running but no files are ever copied to the Done dir.

This command when I paste it into cmd works fine, everything looks the exact same except the files actually show up when it's done.

Some of the files are on a file share that requries permissions (my Windows auth) that I have. Does it use them when I enter it into the command line and not when getRuntime.exec() does? Is there anyway to pass it permissions or something? Not sure kind of lost from here.


+ This is in WinXP 32
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First search for and read the Javaworld article "When Runtime.exec() won't". It's a must-read when dealing with Process.
 
C La
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Came across it in my searches earlier. It does work already it just isn't copying the files. Maybe it is the perl script the command line calls that is lacking the permissisons to move files? I don't know...
 
C La
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have also tried removing the first command so it is single using a overloaded version of getRuntime.exec() and it does the exact same thing. Everything looks like it's working but no files are copied to or from C:\MyBuildDir or Done

 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you should try this version ....


And try to append ">c:\\error.log" to the end of the command, you'll see what is going on in the background.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you consuming the std out and std err streams created by the Process? If you don't do this right (with separate Threads) you get mystery hangs.

Read the JavaDocs for java.lang.Process

Bill
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C La wrote:Came across it in my searches earlier. It does work already it just isn't copying the files. Maybe it is the perl script the command line calls that is lacking the permissisons to move files? I don't know...


And did you implement it? Do you have a StreamGobbler for both the output and error streams? If so, what output is being reported?
 
C La
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was before getting the output but not the error stream. I believe it is implimented properly. I am not getting any additional information from the error stream. The errors could be happening in the perl file which does the copying and isn't displaying the errors maybe...

 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are doing it wrong - there need to be separate Threads running for both the std out and std err streams. As I already pointed out once.

Read the java.lang.Process docs.

Bill

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!