简体   繁体   English

使用Python Subprocess并自动获取实时输出

[英]Getting realtime output using Python Subprocess and autoit

I am trying to approach to a process from my python script. 我正在尝试从我的python脚本进行处理。 I am trying to get a value that i can get from only autoit, i want it from specific process 我试图获得只能通过autoit获得的价值,我希望从特定流程获得它

process2 = subprocess.Popen([dpa_path], stdin = subprocess.PIPE,stdout = subprocess.PIPE)

#I tried some ways, and none of them worked. examples:
process2.stdout.read(int(process2.stdin.write(str(Auto.ControlCommand("", "", "TBitBtn2" ,"IsVisible", "")))

or 要么

process2.stdout.read(Auto.ControlCommand("", "", "TBitBtn2" ,"IsVisible", ""))

for autoit I am using 我正在使用自动

from win32com.client import Dispatch
Auto = Dispatch("AutoItX3.Control") 

and for the process I am using 对于我正在使用的过程

import subprocess

how can i get the value that is retuned from the Auto.ControlCommand? 我如何获得从Auto.ControlCommand重新调整的值?

first of all, AFAIK there is no direct way to directly get the returned value. 首先,AFAIK没有直接获取返回值的直接方法。 Depending on what you need to do with the returned value you can choose from some options. 根据需要对返回值执行的操作,可以从一些选项中进行选择。

  1. Run AutoIt script from SciTE-Lite editor (bundled with AutoIt). 从SciTE-Lite编辑器(与AutoIt捆绑在一起)中运行AutoIt脚本。 Go for Tools -> Go. 转到工具->转到。 That way, anything you print , will be printed in internal console of SciTE. 这样,您打印的任何内容都将在SciTE的内部控制台中打印。 Use ConsoleWrite("string") 使用ConsoleWrite("string")
  2. Pop a MsgBox like this: 像这样弹出一个MsgBox:

AutoIt MsgBox

For more detailed info on how to use MsgBox refer to AutoIt doc: https://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm 有关如何使用MsgBox的更多详细信息,请参考AutoIt文档: https : //www.autoitscript.com/autoit3/docs/functions/MsgBox.htm

Let me know if this fixes your problem. 让我知道这是否可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM