1

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)
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
kocmoc
  • 65
  • 1
  • 7

1 Answers1

1
  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 ...
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • I put this in a .bat file but it didn't recognize the syntax. I also tried running at the command prompt and it asks for "More?" after each entry. How do you send this list of commands without user interaction? – Sanjo Apr 21 '22 at 15:12
  • @Sanjo If you have a problem, please post a question with [mcve]. *"Didn't recognize the syntax"* is too vague. – Martin Prikryl Apr 22 '22 at 06:24
  • is this code supposed to be in .bat file? I'm talking about the ( echo. echo username echo mkdir /test timeout /t 5 > nul taskkill /f /im plink.exe > nul ) | plink ... – Sanjo Apr 22 '22 at 15:46