1

I have an RFID reader that I need to download data from periodically via a serial port connection (serial to USB). I have been using PuTTY to connect to the reader. I saved a session in PuTTY with all of the correct parameters for the reader and named it "test". I also used "All session output" under Logging so that the output will be stored in a file. I access the session via the Windows 10 command line like this:

putty.exe -load "test"

and the terminal appears just like it would if I went though the GUI. I then have a series of commands that I would like to run in the PuTTY terminal which provides the output data I need. For example lets say the commands I need to run are:

DT
UH
SS
TF

I would like to automate this process somehow, so that every time I connect to the reader the same commands are run. Can a script be written to do this in PuTTY or can these commands be sent to PuTTY from the command line? Could someone demonstrate how to do this?

Martin Prikryl
  • 167,268
  • 50
  • 405
  • 846
Ryan
  • 984
  • 4
  • 10

1 Answers1

0

PuTTY is not the right tool for automation, use Plink:
Automating command/script execution using PuTTY

You just need to know specifying the commands on Plink command-like or with the -m switch commonly used with Plink (the -m even with PuTTY) works with the SSH protocol only.

With other protocols, notably with the serial connections, you can use the input redirection only (also covered in my answer to the question linked above), like this:

plink.exe -load "my serial connection" < c:\local\path\commands.txt

or

plink.exe -serial COMx -sercfg 19200,8,n,1,X < c:\local\path\commands.txt

See also Execute a command on device over serial connection with Plink.

(And this is something that you cannot do with GUI PuTTY, so for this approach, Plink is the way to go).

Martin Prikryl
  • 167,268
  • 50
  • 405
  • 846
  • Can this be used to capture the output of a serial command that receives a response from the target? I would like to capture and process the information that returns. – Sanjo Apr 21 '22 at 14:53
  • @Sanjo Yes, just redirect the plink output somewhere. If you need further assistance, please ask a new question. – Martin Prikryl Apr 22 '22 at 06:21
  • I asked a new question here: https://stackoverflow.com/questions/71973884/using-plink-to-write-a-file-to-a-com-port-and-read-back-the-response-from-the-ta – Sanjo Apr 22 '22 at 19:45