Go Premium for a chance to win a PS4. Enter to Win

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

Runtime.getRuntime().exec(cmdArray) is not properly moving all files

I am running the following code, but it always moves exactly 6 files, no matter what files I put into the incoming directory, leaving the rest of the files behind and indicating that the process is still running.

What could be a possible reason for this?
package com.hsc.underwriting.test;
 
import org.junit.Test;
 
public class IOTest {
	@Test
	public final void testAutoMove() {
		try {
			String[] cmdArray = new String[5];
			cmdArray[0] = "cmd.exe";
			cmdArray[1] = "/C";
			cmdArray[2] = "move";
			cmdArray[3] = "incoming\\**";
			cmdArray[4] = "outgoing\\";
 
			Process autoMoveProcess = Runtime.getRuntime().exec(cmdArray);
			//Thread.sleep(10000);
			autoMoveProcess.waitFor();
			autoMoveProcess.destroy();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
 
}

Open in new window

0
aturetsky
Asked:
aturetsky
  • 2
1 Solution
 
CEHJCommented:
That will produce output that you need to consume on separate threads. See

http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
0
 
objectsCommented:
Is the process completing?  If not, try this:

http://helpdesk.objects.com.au/java/runtime-exec-locks-up

0
 
aturetskyAuthor Commented:
CEHJ, the solution they provided worked great.  Thanks !!!!!!!!!!!!!!
0
 
CEHJCommented:
:-)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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