invoking a call to a window executable fails when request output to file

Hi,

When invoking a call to a window executable it fails(returns 1 instead of 0) when requesting output to file by using "> filename.txt". This nornally works when run directly within a

windows command prompt, and it also works if I don't add the "> filename.txt" at the end. Also instead of outputting to a file I would like the same called executable to output to a memory variable that I can extract data without going to a external text file.

Below is the .java file

package com.insequence.gv;

public class Jinvoker {

public static int invoke(String program) throws java.io.IOException, java.lang.InterruptedException

{

System.out.println("invoking program: " + program);

Process p = Runtime.getRuntime().exec(program);

int exitValue = p.waitFor();

return exitValue;

}

public static void main(String[] argv)

{

try

{

System.out.println("invoker start");

//int retval = invoke("c:\\tvalesky\\java\\invoker\\targetexe arg1 arg2 arg3");

//int retval = invoke("C:\\Program Files\\FWTools1.1.0\\bin\\gdalinfo.exe C:\\data\\EarthData2005\\Ortho\\no_collaged.tif");

String arg1 = "C:\\data\\EarthData2005\\Ortho\\no_collaged.tif > c:\\testing.txt";

//String arg1 = "C:\\data\\EarthData2005\\Ortho\\no_collaged.tif";

int retval = invoke("C:\\Program Files\\FWTools1.1.0\\bin\\gdalinfo.exe " + arg1);

//int retval = invoke("C:\\Program Files\\FWTools1.1.0\\bin\\gdalinfo.exe");

//String arg1 = "-s_srs epsg:26915 -t_srs epsg:4326 C:\\data\\EarthData2005\\Ortho\\no_collaged.tif C:\\data\\EarthData2005\\Ortho\\no_collaged2.tif";

//int retval = invoke("C:\\Program Files\\FWTools1.1.0\\bin\\gdalwarp.exe " + arg1);

//int retval = invoke("C:\\testing.bat C:\\data\\EarthData2005\\Ortho\\no_collaged2.tif");

System.out.println("invoker end: returned " + retval);

}

catch(java.io.IOException e)

{

System.out.println("IOException caught: " + e);

}

catch(java.lang.InterruptedException e)

{

System.out.println("InterruptedException caught: " + e);

}

}

}

Thanks,

John Mitchell

[2221 byte] By [mitchelljja] at [2007-11-26 16:59:55]
# 1

Well, if you ultimately want the output from the process, you don't need to redirect it to a file first. Just read from the standard output of the process. See [url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Process.html#getInputStream()]Process.getInputStream[/url] and Process.getErrorStream. You'll need to read from both simultaneously so you'll need to create two threads. You could also use [url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ProcessBuilder.html]ProcessBuilder[/url] if you're using Java 1.5

Jasprea at 2007-7-8 23:27:42 > top of Java-index,Java Essentials,Java Programming...
# 2
Read this! http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html~Tim
SomeoneElsea at 2007-7-8 23:27:42 > top of Java-index,Java Essentials,Java Programming...