windowsbatch-fileserial-portplink

Send commands via COM port using plink and exit


I need to execute one or more commands via COM port (from console) on an embedded Linux device. I am trying to use plink on a Windows machine but it doesn't work.

I've tried different cases, one of them is:

echo "mkdir /test" | plink -batch -serial \\\\.\\com4 -sercfg 115200,N,8 -l root

I have a couple of problems:

  1. hangs until you press Enter, after that you will have "login:", and will not exit
  2. the command doesn't work (doesn't create a dir)

Solution

    1. Use echo. to send empty line = Enter
    2. Another echo to send the login
    3. In Windows (contrary to *nix shells), if you do echo "foo", you get "foo", not foo. So you might need echo mkdir ..., not echo "mkdir ...".
    4. You will need to kill the session somehow. There's no signal you can send to plink to close it. And as the serial connection is not really a connection, it cannot be closed remotely (the way an SSH server can close the connection, when you send an exit command). So all you can probably do is to kill the plink, e.g. using taskkill.
    (
      echo.
      echo username
      echo mkdir /test
      timeout /t 5 > nul
      taskkill /f /im plink.exe > nul
    ) | plink ...