views:

1563

answers:

7

Hi,

I need to create a BAT file to run an application through telnet, but as far as I know there is no way to do this on DOS. Telnet does not allow any command to be sent to the remote machine at the very instant of the connection, and each subsequent command in the BAT file would only be executed after telnet stops. This hypothetical piece of code illustrates what I want to do:

telnet 100.99.98.1 "C:\Application\app.exe -a -b -c"

And that would run the app.exe on the machine 100.99.98.1 with three parameters. Despite my efforts, nothing worked. Is there a way to do that?

Tks,

Pedrin Batista

+2  A: 

Using telnet in the way you want to is imho not possible.

You could you secure shell (ssh), but a ssh server has to run on the remote machine (100.99.98.1 in you case).

EDIT:

See http://sshwindows.sourceforge.net/ for a ssh client and server (based on cygwin) for Windows.

Frank Grimm
That's right, telnet is not designed for non-interactive uses. :-P
Chris Jester-Young
A: 

Does your telnet app need to run in a command window, or do you only need to start it from the command line? If you want to "launch and forget," you might consider a scriptable terminal program such as the free TeraTerm. You can launch it from the command line with the start command and let it execute a script in the background.

Adam Liss
Unfortunately I need the command window due to interaction.
Pedrin
+3  A: 

Have you tried:

echo "c:\application\app.exe -a -b -c" | telnet 100.99.98.1

this won't work if the remote telnet server requires a username and password, though.

Alnitak
Beat me by seconds!
S.Lott
SO says 3 minutes ... maybe that's why my code is always late. :-)
Adam Liss
+3  A: 

Due to your paths I'm assuming you are working on a windows platform. I'd suggest looking at PsExec from Microsoft/SysInternals which allows you to execute a command on a remote machine.

PsExec is part of the excellent free PsTools package from Mark Russinovich. SysInternals was recently purchased by Microsoft, but the tools remain free.

This does not, however, work over the internet. It uses windows networking port 445 and should only be used on local networks. If you need that I'd suggest using SSH.

Todd
+2  A: 

Have you tried the following?

telnet 100.99.98.1 <someScript

Where someScipt has your command, e.g., C:\Application\app.exe -a -b -c

Have you looked at a Remote Shell daemon for windows? This is probably a lot better than telnet.

S.Lott
A: 

give expect a try

from the webpage:

Expect is a tool for automating interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, etc. Expect really makes this stuff trivial. Expect is also useful for testing these same applications.

PW
A: 

You might consider using Cygwin (which provides a Linux-/Unix-like command-line environment running on Windows). A wide range of standard tools, including shell scripting, is available as part of Cygwin.

joel.neely