在启动本地exe文件后,运用脚本输入参数,运行结果出现以下提示:
Cannot read keys when either application does not have a console or when console input has been redirected from a file. Try Console.Read.
该问题如何解决呢?
以下是运行代码:
import subprocess
import os,sys
import time
sir_util2_path = r'C:\Users\75622\Desktop\SendService.v1.3.1.1\SendService.ConsoleApp\SendService.ConsoleApp.exe'
def sir_to_geotiff():
param = ["22222", "33333333"]
cmd = [sir_util2_path]
p = subprocess.Popen(cmd,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
out, err = p.communicate(''.join(map(str, param)))
if p.returncode != 0:
raise subprocess.CalledProcessError(p.returncode, cmd, output=(out,err))
if name == "main":
try:
sir_to_geotiff()
except subprocess.CalledProcessError as e:
err = e.output[0]
print(err)
以下是运行结果:
希望实现的结果:
自动输入账号,实现登录,抓取控制台的所有信息并以字符串的方式打印出来
以下截图是手动输入客户端的信息:
popen的时候加个参数,shell=True
cmd应该是个字符串,参数之间用空格分割,不要传入list