Problem to use : Runtime.getRuntime().exec(cdCmd);

Hi,

i have two files : test.java and output.java

both are in one folder named : myapp

--output.java

public class output

{

public static void main(String a[])

{

System.out.println("it's running.....");

}

}

//-

test.java--

import java.io.*;

public class test

{

public static void main(String a[])

{

String[] cdCmd = { "java output"};

try {

Runtime.getRuntime().exec(cdCmd);

}

catch (IOException ioe)

{

System.out.println(ioe.getMessage());

}

}

}

now , when i run....test.java file to see output of output.java class..it gives exception...

CreateProcess: "java output" error=2

what is problem?

[783 byte] By [pvanjavaa] at [2007-11-27 9:31:44]
# 1

Hi,

Try this...

import java.io.InputStream;

public class test {

public static void main(String a[]) {

String cdCmd2 = "java output";

try {

Process child = Runtime.getRuntime().exec(cdCmd2);

int i = child.waitFor();

// Get the input stream and read from it

InputStream in = child.getInputStream();

int c;

while ((c = in.read()) != -1) {

System.out.print((char) c);

}

in.close();

System.out.println(child.exitValue());

} catch (Exception ioe) {

ioe.printStackTrace();

}

}

}

Regards,

Bhavani P Polimetla

polimetlaa at 2007-7-12 22:47:22 > top of Java-index,Java Essentials,New To Java...
# 2
Runtime.getRuntime().exec(cdCmd);Afaik cdCmd is not executable.if you want to print cdCmd use System.out.prinln();
deAppela at 2007-7-12 22:47:22 > top of Java-index,Java Essentials,New To Java...
# 3
> Hi,> > Try this...Hi,Read this... http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
aniseeda at 2007-7-12 22:47:22 > top of Java-index,Java Essentials,New To Java...