executing remote command

C

Carlos

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 didn't get any answer. My code is really simple. I DON'T 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();
}
}
 
C

Cid

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 didn't get any answer. My code is really simple. I DON'T 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 don't have terminating line feeds which
the shell is probably waiting for. Does it even get that far?
 
N

Nigel Wade

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 didn't get any answer. My code is really simple. I DON'T 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 don't 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. Don't ask me how...

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

zoopy

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 didn't get any answer. My code is really simple. I DON'T 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top