在使用 Plink 向串口发送登录和命令之间等待 [英] Wait between sending login and commands to serial port using Plink

查看:21
本文介绍了在使用 Plink 向串口发送登录和命令之间等待的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过PLINK中的串口进行连接.问题是代码(下面)不起作用,因为文件 remove.txt 是一次性发送的,而终端要求登录,然后才开始要求命令.有没有可能先登录然后执行命令文件?test 保存串行会话(com5 baud 115200)

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)

命令:

C:PROGRA~1PuTTYplink -load test < C:Usersqj2p70Desktop
emove.txt

remove.txt 文件:

root
root
cd /cfg_usr/delphi/etc
rm vip_coding_yes

推荐答案

如果我理解正确的话,问题是串口上的设备丢弃了一个来得太早的输入.

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

您可以通过在各个输入/行之间暂停来解决这个问题.但是你不能使用输入文件.您需要使用一个程序"来生成输入,该程序可以执行暂停并将输入传送到 plink.实现此类程序的一种简单方法是在批处理文件中使用复合语句:

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

<小时>

以上将产生 Windows CRLF 行尾.也许您的设备需要 *nix CR 行尾.您可以尝试以下 PowerShell 脚本 (script.ps1):

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

并像这样使用它:

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

这篇关于在使用 Plink 向串口发送登录和命令之间等待的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆