PuTTY – Run Batch Commands Through Serial Connection

batchputtyserial

I have a sequence of commands which I use to update the firmware on my Linux machine. When I connect to the machine using a serial connection I can type the commands one-by-one and they work fine. I would like to automate this procedure by running the commands in a batch file.

I have a profile for my serial connection saved as 'i5IS-COM4' so I run my first batch file , 'send.bat' , which reads:

commands.bat |  putty -load i5IS-COM4

and commands.bat reads:

echo "this command works!"

When I run 'send.bat' it correctly opens a terminal and connects to my Linux machine but the echo command is not working. If anyone could help me get my batch file to work it would be greatly appreciated!

I have looked over the following post and a number of others, but I have yet to find a solution to my problem.

Run multiple commands from a file after logging into PuTTY from a bat file

edit:

When I use command redirection using plink instead of putty, I just get an empty terminal. Running the following command:
start plink.exe -load i5IS-COM4 < commands.txt
with commands.txt as follows:
echo "this command works!"; /bin/bash
returns the following terminal:
enter image description here

Best Answer

PuTTY is GUI application, not a console application. You cannot use input/output redirection with a GUI application.

There's no way to execute a command on the server automatically with PuTTY over a serial connection.


Though you should be able to use Plink (PuTTY command-line connection tool).

Plink is an equivalent of PuTTY, except that it is a console application, so you can use input/output redirection with it:

commands.bat | plink -load i5IS-COM4

Though as your "bat" file is actually not a batch file (that would produce the commands for the device), but a text file that directly contains the commands for the device, you want to use the contents of the file as an input, rather than output of its execution:

plink -load i5IS-COM4 < commands.bat
Related Question