serial-portremote-accessputtyplink

Execute a command on device over serial connection with Plink


This is the first time that I am trying to write a "plink" command that will connect to a device and to have a remote command executed afterwards. And I am blocked so far.

Here is the command I have tried.

plink -v device ( execute shell; whoami)

I was expecting the full command process finished right away, but somehow, it hangs. here is the screenshot after I have run the above command,

plink -v device ( execute shell; whoami) 
Opening serial device COM1
Configuring baud rate 115200
Configuring 8 data bits
Configuring 1 data bits
Configuring no parity
Configuring XON/XOFF flow control

And after i have pushed the extra "Enter" key from my keyboard, then I see the popup of device name, which means the connection part is ready,

plink -v device ( execute shell; whoami) 
Opening serial device COM1
Configuring baud rate 115200
Configuring 8 data bits
Configuring 1 data bits
Configuring no parity
Configuring XON/XOFF flow control

FX04DN4N16000408  #

What I don't understand is why do I need to run this extra manual step ?

Thanks,

Jack


Solution

  • Specifying a command on Plink command-line (or with -m switch) works with SSH only, not with serial (or other) connections. The reason is that those connections have no interface for executing a command. They only have input/output.

    So, you can use an input redirection with the serial connection, instead. Like this:

    plink.exe ... < commands.txt
    

    or

    (
      echo your command 1
      echo your command 2
      echo your command 3
    ) | plink.exe ...
    

    Related question:
    Authenticating serial connection in Plink


    You will also probably need to terminate the Plink somehow:
    Send commands via COM port using plink and exit