【问题标题】:Running command using Plink through Python and serial port?通过 Python 和串口使用 Plink 运行命令?
【发布时间】:2021-09-15 07:06:07
【问题描述】:

我可以打开一个新的cmd窗口并通过Python连接plink和串口。

import os
import subprocess

os.system("start cmd /k plink.exe -serial COM4 -sercfg 115200,8,n,1,N") 

这里还不错,但是当我想运行 ifconfig 时,它不起作用。

os.system("ifconfig")

【问题讨论】:

    标签: python serial-port plink


    【解决方案1】:

    首先,考虑使用原生 Python 串行连接实现,例如 pySerial,而不是运行控制台应用程序 (plink)。

    见Full examples of using pySerial package。


    无论如何,如果您运行一个 Windows 批处理文件来执行您的 Python 代码,它也不会执行您想要的操作:

    start cmd /k plink.exe -serial COM4 -sercfg 115200,8,n,1,N
    ifconfig
    

    ifconfig 不是顶级命令。这是需要Plink执行的东西。

    您必须将命令提供给plink 标准输入,请参阅:
    Execute a command on device over serial connection with Plink

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-09
      • 2017-09-08
      • 2011-12-25
      • 2015-01-15
      • 1970-01-01
      相关资源
      最近更新 更多