Solved

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

Posted on 2009-06-30
4
308 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

630 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