Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
csduvvuri@gmail.com - 28 Jun 2006 07:59 GMT
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
Roland de Ruiter - 28 Jun 2006 10:34 GMT
> 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
[quoted text clipped - 10 lines]
> Thanks
> Chandoo

In your program you are using the exec method that takes a String array
as arguments. In this array the first element is the program to be
executed, the remaining elements are the arguments for this program.
Your array has only one element: it tries to start the program "ssh2 -l
username serverbox.exe", which obviously didn't exist.

Split the command and its arguments yourself [2], or let the
Runtime.exec(String) do it four you [1].

So, use [1]:
   String command = "ssh2 -l username  serverbox";
   Process p = Runtime.getRuntime().exec(command);
<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html#exec(java.lang.String)>

Or [2]:
   String[] cmdarray = {"ssh2", "-l", "username", "serverbox"};
   Process p = Runtime.getRuntime().exec(cmdarray);
<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Runtime.html#exec(java.lang.String[])>
Signature

Regards,

Roland



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.