LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-07-2009, 03:42 PM   #1
john smith
LQ Newbie
 
Registered: Mar 2009
Posts: 14

Rep: Reputation: 0
Question help in swing program


hi i am using this swing program for remote login ,using ssh command but i am not abale to log into nremote pc.the code is
import javax.swing.*;
import java.io.*;
class robinswing{
String username="adarsh",ip_address="10.10.177.123";
robinswing()
{
JFrame jfrm= new JFrame ("a simple swing application");
jfrm.setSize(275,100);
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel jlab=new JLabel("aswing demo");
jfrm.add(jlab);
jfrm.setVisible(true);
}
void RemoteLogin()
{
String login = username + "@" + ip_address;
String prefix = "ssh";
String fullCommand = prefix + " "+login+" ";
System.out.println("Executing ");
System.out.println("Full command:");

try
{
Process p = Runtime.getRuntime().exec(fullCommand);
}
catch (IOException a){
System.out.println("I/O Exception executing a remote command");

}
}


public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable(){
public void run(){
robinswing a=new robinswing();
a.RemoteLogin();
}
});
}
}

WHAT CHANGES SHOULD I MAKE TO THE CODE
 
Old 05-07-2009, 06:32 PM   #2
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by john smith View Post
Code:
import javax.swing.*;
import java.io.*;
class robinswing
{
    String username = "adarsh";
    String ip_address = "10.10.177.123";
    robinswing()
    {
        JFrame jfrm = new JFrame("a simple swing application");
        jfrm.setSize(275,100);
        jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JLabel jlab = new JLabel("aswing demo");
        jfrm.add(jlab);
        jfrm.setVisible(true);
    }
    void RemoteLogin()
    {
        String login = username + "@" + ip_address;
        String prefix = "ssh";
        String fullCommand = prefix + " " + login + " ";
        System.out.println("Executing ");
        System.out.println("Full command:");

        try
        {
            Process p =  Runtime.getRuntime().exec(fullCommand);
        } catch (IOException a)
        {
            System.out.println("I/O Exception executing a remote command");
        }
    }


    public static void main(String[] args)
    {
        SwingUtilities.invokeLater(new Runnable(){
                                       public void run(){
                                           robinswing a=new robinswing();
                                           a.RemoteLogin();
                                       }
                                   });
    }
}
Here are some things to try:
  • Check the value of p after the call to exec
  • Add a catch(Exception e) to see if some other exception occurred
  • Print out the command string to make sure it is correct (the trailing space might be confusing Java's tiny brain)
 
Old 05-08-2009, 12:43 AM   #3
jay73
LQ Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 133Reputation: 133
How are you going to do I/O with that application? It hasn't got any streams at all.
 
Old 05-08-2009, 07:47 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 05-08-2009, 11:50 PM   #5
john smith
LQ Newbie
 
Registered: Mar 2009
Posts: 14

Original Poster
Rep: Reputation: 0
the output of the program is
Executting
Fullcommand
adarsh@10.10.177.123 password:
When i manually providing the password it is not accepting,how to pass the password through the program
 
Old 05-09-2009, 10:52 AM   #6
David1357
Senior Member
 
Registered: Aug 2007
Location: South Carolina, U.S.A.
Distribution: Ubuntu, Fedora Core, Red Hat, SUSE, Gentoo, DSL, coLinux, uClinux
Posts: 1,302
Blog Entries: 1

Rep: Reputation: 107Reputation: 107
Quote:
Originally Posted by john smith View Post
how to pass the password through the program?
You will have to hook up an I/O stream to that process somehow.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
what is import javax.swing.*; Dutchman Programming 4 06-16-2005 10:12 AM
java swing JTextArea gauravbagga Programming 1 05-23-2005 04:34 AM
Am I the only one fed up with Swing? eantoranz Programming 13 04-29-2005 08:26 PM
getting javax.swing.* to appear student04 Programming 8 10-05-2004 10:06 AM
Swing 1.1 or 1.2 and CLASSPATH jboo Linux - Software 0 02-07-2003 11:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration