Solved

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

Posted on 2009-06-30
4
298 Views
Last Modified: 2012-05-07
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
Comment
Question by:aturetsky
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 24750174
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
 
LVL 92

Expert Comment

by:objects
ID: 24750370
Is the process completing?  If not, try this:

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

0
 
LVL 1

Author Comment

by:aturetsky
ID: 24750393
CEHJ, the solution they provided worked great.  Thanks !!!!!!!!!!!!!!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24750406
:-)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now