Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

batch file - Wait between sending login and commands to serial port using Plink

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~1PuTTYplink -load test < C:Usersqj2p70Desktop
emove.txt

remove.txt file:

root
root
cd /cfg_usr/delphi/etc
rm vip_coding_yes
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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~1PuTTYplink -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~1PuTTYplink -load test

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...