2

I can open a new cmd window and connect with plink and serial port through Python.

import os
import subprocess

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

Still good here, but when I want to run ifconfig, it didn't work.

os.system("ifconfig")
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Jean
  • 29
  • 1
  • 4

1 Answers1

0

First, consider using native Python serial connection implementation, like pySerial, instead of running a console application (plink).

See Full examples of using pySerial package.


Anyway if you run a Windows batch file that does what your Python code, it won't do what you want either:

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

The ifconfig is not a top-level command. It's something that needs to be executed by Plink.

You have to feed the command to the plink standard input, see:
Execute a command on device over serial connection with Plink

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992