1 16 package examples; 17 18 import java.io.IOException ; 19 import org.apache.commons.net.bsd.RExecClient; 20 21 34 35 public final class rexec 37 { 38 39 public static final void main(String [] args) 40 { 41 String server, username, password, command; 42 RExecClient client; 43 44 if (args.length != 4) 45 { 46 System.err.println( 47 "Usage: rexec <hostname> <username> <password> <command>"); 48 System.exit(1); 49 return ; } 51 52 client = new RExecClient(); 53 54 server = args[0]; 55 username = args[1]; 56 password = args[2]; 57 command = args[3]; 58 59 try 60 { 61 client.connect(server); 62 } 63 catch (IOException e) 64 { 65 System.err.println("Could not connect to server."); 66 e.printStackTrace(); 67 System.exit(1); 68 } 69 70 try 71 { 72 client.rexec(username, password, command); 73 } 74 catch (IOException e) 75 { 76 try 77 { 78 client.disconnect(); 79 } 80 catch (IOException f) 81 {} 82 e.printStackTrace(); 83 System.err.println("Could not execute command."); 84 System.exit(1); 85 } 86 87 88 IOUtil.readWrite(client.getInputStream(), client.getOutputStream(), 89 System.in, System.out); 90 91 try 92 { 93 client.disconnect(); 94 } 95 catch (IOException e) 96 { 97 e.printStackTrace(); 98 System.exit(1); 99 } 100 101 System.exit(0); 102 } 103 104 } 105 106 | Popular Tags |