Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

xxcopy hangs

I'm using xxcopy with the code below to do a recursive copy of a given directory.  The problem I have is that if I generate an error by leaving a file to be copied open, the process never returns, p.waitFor() just hangs.  I'm using the /YY switch which should mean that all prompts are suppressed, so I don't understand why it hangs up when there's an error..
    String sSource = getBasePath();
    String[] sArrArgs = new String[14];
    sArrArgs[0] = "cmd";
    sArrArgs[1] = "/c";
    sArrArgs[2] = "xxcopy";
    sArrArgs[3] = "/CLONE";
    sArrArgs[4] = "/PZ0";
    sArrArgs[5] = sSource;
    sArrArgs[6] = getDestBasePath();
    sArrArgs[7] = "/I";
    sArrArgs[8] = "/YY";
    sArrArgs[9] = "/PB";
    sArrArgs[10] = "/H";
    sArrArgs[11] = "/Q3";
    sArrArgs[12] = "/k0";
    sArrArgs[13] = "/VL";
   Process p = Runtime.getRuntime().exec(sArrArgs);
   p.waitFor();
   iRtn = p.exitValue();
0
jkavx
Asked:
jkavx
  • 3
  • 2
1 Solution
 
jkavxAuthor Commented:
So the code in this sample should run in a separate thread concurrent with the code I"m currently executing.  Something like this?
  ...
   sArrArgs[13] = "/VL";
   StreamGobbler sg = new StreamGobbler(new InputStream(), "xx");
   Thread thread = new Thread(sg);
   thread.start();
   Process p = Runtime.getRuntime().exec(sArrArgs);
   p.waitFor();
   iRtn = p.exitValue();
0
 
jkavxAuthor Commented:
sArrArgs[13] = "/VL";
Process p = Runtime.getRuntime().exec(sArrArgs);
StreamGobbler sg = new StreamGobbler(p.getInputStream(), "xx");
Thread t = new Thread(sg);
t.start();
p.waitFor();
iRtn = p.exitValue();
0
 
objectsCommented:
yes, and another thread if you also need to swallow stderr

0
 
jkavxAuthor Commented:

This works.  Thanks.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now