java.io.IOException: CreateProcess: " ssh2 -l username serverbox" error=2



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

.



Relevant Pages

  • Re: maybe a popen question... or something else?
    ... I want to invoke foo.exe from a Python script (using whatever will ... gets these args for processing ... When a command is invoked the arguments are taken from the command line, so it isn't possible to pass further arguments at a later time. ...
    (comp.lang.python)
  • maybe a popen question... or something else?
    ... foo.exe is a command line tool that can take a number of different ... I want to invoke foo.exe from a Python script (using whatever will ... gets these args for processing ...
    (comp.lang.python)
  • Re: Windows Genuine Advantage -- Indeed?
    ... SEND command would then automatically invoke the MAIL command. ... exec, fully logged in. ...
    (rec.arts.sf.fandom)
  • Re: tex4ht and Miktex 2.5
    ... fix the paths in the tex4ht and t4ht records, and invoke the command ... That at least gives us a approach to run tex4ht with miktex 2.5. ...
    (comp.text.tex)
  • Re: Segmentation fault error
    ... contains the command by which the program was invoked. ... Whether or not argc is zero or non-zero argvis always ... cases, the command used to invoke a program is some form of its name, ... string could be set to any name before invoking your program, ...
    (comp.lang.c)