C
csduvvuri
i have written a java program to connect to a Server box using SSH2 but
when i am executing the code its showing some eception. first I am
trying to invoke command prompt but the console is disappearing as soon
it is invoked.
the exception is
java.io.IOException: CreateProcess: "ssh2 -l username serverbox "
error=2
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Win32Process.java:87)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:582)
at java.lang.Runtime.exec(Runtime.java:505)
at java.lang.Runtime.exec(Runtime.java:471)
at Sam.doExec2(Sam.java:29)
at Sam.main(Sam.java:35)
Exception in thread "main"
The code is
import java.io.IOException;
public class Sam{
static void doExec1() throws IOException {
// invoke a shell and give command to it
Runtime runtime = Runtime.getRuntime();
String[] args =
new String[]{"cmd"};
Process p = runtime.exec(args);
System.out.println("The command prompt");
}
static void doExec2() throws IOException {
// invoke a shell and give command to it
System.out.println("the second method");
Runtime runtime = Runtime.getRuntime();
System.out.println("the second method1");
String[] args =
new String[]{"ssh2 -l username serverbox "};
System.out.println("the second method2");
Process p = runtime.exec(args);
System.out.println("the second method3");
}
public static void main(String[] args) throws IOException {
doExec1();
doExec2();
}
};
please anyone help me
Thanks
Chandoo
when i am executing the code its showing some eception. first I am
trying to invoke command prompt but the console is disappearing as soon
it is invoked.
the exception is
java.io.IOException: CreateProcess: "ssh2 -l username serverbox "
error=2
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Win32Process.java:87)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:582)
at java.lang.Runtime.exec(Runtime.java:505)
at java.lang.Runtime.exec(Runtime.java:471)
at Sam.doExec2(Sam.java:29)
at Sam.main(Sam.java:35)
Exception in thread "main"
The code is
import java.io.IOException;
public class Sam{
static void doExec1() throws IOException {
// invoke a shell and give command to it
Runtime runtime = Runtime.getRuntime();
String[] args =
new String[]{"cmd"};
Process p = runtime.exec(args);
System.out.println("The command prompt");
}
static void doExec2() throws IOException {
// invoke a shell and give command to it
System.out.println("the second method");
Runtime runtime = Runtime.getRuntime();
System.out.println("the second method1");
String[] args =
new String[]{"ssh2 -l username serverbox "};
System.out.println("the second method2");
Process p = runtime.exec(args);
System.out.println("the second method3");
}
public static void main(String[] args) throws IOException {
doExec1();
doExec2();
}
};
please anyone help me
Thanks
Chandoo