Wait between sending login and commands to serial port using Plink

百般思念 提交于 2019-12-10 11:43:29

问题


I want to make connection by serial port in PLINK. The problem is that the code (below) doesn't work because file remove.txt is all sent at once, while terminal is asking for a login and before it starting asking for commands. There is any possibilities to login first and then execute command file? The test is saved serial session (com5 baud 115200)

Command:

C:\PROGRA~1\PuTTY\plink -load test < C:\Users\qj2p70\Desktop\remove.txt

remove.txt file:

root
root
cd /cfg_usr/delphi/etc
rm vip_coding_yes

回答1:


If I understand correctly, the problem is that the device on the serial port discards an input that comes too early.

You can solve that by pausing between individual inputs/lines. But then you cannot use an input file. You need generate the input using a "program" that can do the pauses and pipe that input to plink. An easy way to implement such program is using a compound statement in a batch file:

(
  echo root
  timeout /t 5 > nul
  echo root
  timeout /t 5 > nul
  echo cd /cfg_usr/delphi/etc
  timeout /t 5 > nul
  echo rm vip_coding_yes
) | C:\PROGRA~1\PuTTY\plink -load test

The above will produce Windows CRLF line endings. Maybe your device needs *nix CR line endings. You can try the following PowerShell script (script.ps1):

Write-Host -NoNewline "root`n"
Start-Sleep 5
Write-Host -NoNewline "root`n"
Start-Sleep 5
# ...

And use it like:

powershell.exe -ExecutionPolicy Bypass -File script.ps1 | C:\PROGRA~1\PuTTY\plink -load test


来源:https://stackoverflow.com/questions/55851109/wait-between-sending-login-and-commands-to-serial-port-using-plink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!