Sagewire Logo

executing remote command

5 Message(s) by 4 Author(s) originally posted in java developer


From: cazq1998 Date:   Tuesday, July 27, 2004
Hi, anyone can help me?

I'm working on windows and I want to execute a command on a remote
computer (Unix ) so I try to make a telnet to the specified server but
I did not get any answer. My code is really simple. I DO not WANT TO USE
SOCKETS OR ANY OTHER PROGRAM IN THE SERVER.

Can anyone give some advice, or any suggestion?

SOURCE CODE (this is the source code that I'm using)
-------------------------

import JAVA.io.*;

class test{

public test(){}
public void process (){
try {
// Execute command
String command = "telnet";
Process child = Runtime.getRuntime().exec(command);

OutputStream out = child.getOutputStream();
out.write("open <SERVER_NAME>\n".getBytes()); // Get the input stream and read from it
Input Stream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
System.out.print(""+(char)c);
}
out.write("my_user\n".getBytes());
while ((c = in.read()) != -1) {
System.out.print(""+(char)c);
}
out.write("\n".getBytes());
while ((c = in.read()) != -1) {
System.out.print(""+(char)c);
}
out.write("touch carlos.txt".getBytes());
out.write("exit".getBytes());
in.close();
out.close();
} catch (IOException e) { System.out.println(e.getMessage());
}

}

public static void main(String args[]){
test uno = new test();
uno.process();
}
}


From: Cid Date:   Tuesday, July 27, 2004
wrote in message :

Hi, anyone can help me?
I'm working on windows and I want to execute a command on a remote
computer (Unix) so I try to make a telnet to the specified server but
I did not get any answer. My code is really simple. I DO not WANT TO USE
SOCKETS OR ANY OTHER PROGRAM IN THE SERVER.
Can anyone give some advice, or any suggestion?
SOURCE CODE (this is the source code that I'm using)
-------------------------
import JAVA.io.*;
class test{
public test(){}
public void process(){
try {
// Execute command
String command = "telnet";
Process child = Runtime.getRuntime().exec(command);
OutputStream out = child.getOutputStream();
out.write("open <SERVER_NAME>\n".getBytes());
// Get the input stream and read from it
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
System.out.print(""+(char)c);
}
out.write("my_user\n".getBytes());
while ((c = in.read()) != -1) {
System.out.print(""+(char)c);
}
out.write("\n".getBytes());
while ((c = in.read()) != -1) {
System.out.print(""+(char)c);
}
out.write("touch carlos.txt".getBytes());
out.write("exit".getBytes());
in.close();
out.close();
} catch (IOException e) { System.out.println(e.getMessage());
}
}
public static void main(String args[]){
test uno = new test();
uno.process();
}
}



Hmm, never tried this so I'm guessing. But it might be an issue that
your touch and exit commands do not have terminating line feeds which
the shell is probably waiting for. Does it even get that far?


From: cazq1998 Date:   Tuesday, July 27, 2004
No, I already try with this and it's not working,
anyone can help me?

wrote in message
wrote in message:
Hmm, never tried this so I'm guessing. But it might be an issue that
your touch and exit commands do not have terminating line feeds which
the shell is probably waiting for. Does it even get that far?





From: Nigel Wade Date:   Wednesday, July 28, 2004
wrote in message:

Hi, anyone can help me?
I'm working on windows and I want to execute a command on a remote
computer (Unix) so I try to make a telnet to the specified server but
I did not get any answer. My code is really simple. I DO not WANT TO USE
SOCKETS OR ANY OTHER PROGRAM IN THE SERVER.
Can anyone give some advice, or any suggestion?



I'm not totally sure, but I do not think telnet uses standard input and
standard output for the prompts and to read userid/password. I think it
opens the controlling terminal directly.

I believe under UNIX you can use pseudo-ttys to do this sort of thing,
like the application 'expect' does. Do not ask me how...

Other than that, you might've to open a Socket to the telnet port
whether you want to or not.

--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@xxxxxxxxxxx
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555


From: zoopy Date:   Wednesday, July 28, 2004
wrote in message:

Hi, anyone can help me?



Hello again.

I'm working on windows and I want to execute a command on a remote
computer (Unix) so I try to make a telnet to the specified server but
I did not get any answer. My code is really simple. I DO not WANT TO USE
SOCKETS OR ANY OTHER PROGRAM IN THE SERVER.
Can anyone give some advice, or any suggestion?



See my reply in comp.lang.JAVA.help

Regards,
Z.



Next Message: pager email addresses


Blogs related to executing remote command

[jira] Created: (GERONIMODEVTOOLS-110) Exception in ...
getPublishDirectory(GeronimoServerBehaviour.java:179) at org.eclipse.jst.ws.internal. axis.creation.ui.command.CopyDeploymentFileCommand.execute(CopyDeploymentFileCommand. java:99) at org.eclipse.wst.command.internal.env.core.fragment. ...

PHP coders
In theory the rate should be comparable with a comparable Java front-end ... Can they write the code to execute a simple shell command from PHP and do ... Can they code using Remote Scripting via iframes or explain how it could be done? ...

window.open in java script
window.open in java script - function java list script, all movie online scripts, ... finding movie nemo script, execute perl script, free java script applets, ... basic german, quark express basic tips, mci command for visual basic, ...

Web Services in Java (Part 1)
This interface must extend the java.rmi.Remote interface. And each method in your interface must throw java.rmi. ... Whether you use the ant file, or the command-line, you must execute this wscompile from the project's root directory, ...

Internet based silent print using scripting languages (client side ...
The browser is not allowed to do certain things by default - execute a snippet of ... The remote printer is a resource that belongs to the remote computer to which it is ... grant access to your instructions to issue a print command, ...

Seven Skeleton Keys For the New Unix User
Jedit is a programming oriented text editor written in Java. ... Vi also starts up very quickly and will run easily over a remote telnet or ssh connection. ... If you have a directory full of commands you never want to execute, ...


Programming | Sports | Autos

copyright 2006
Valid XHTML 1.0 Transitional