Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

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.

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.

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.

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top