首页 > 解决方案 > 如何与子进程交互和使用应用程序的属性

问题描述

我一直在尝试使用“子进程”包从 python 访问 Microsoft Print 3D。

我想要做的是在应用程序中打开一组(.stl)文件并从每个文件中提取一些信息。

#Path of the program
MS_Print_3D = '... /Applications (Parallels)/{c2916d26-d1f5-414d-b261-d6c91024400d} Applications.localized//Print 3D.app'
#STL 3D file
stl_file = '.../994012.stl'

我必须使用选定的(.stl)文件打开并运行程序。但是,我不知道如何访问应用程序内绘制的属性或信息。

p_run = subprocess.run(["open", "-n", MS_Print_3D, stl_file],
                       stdout=subprocess.PIPE,
                       stderr=subprocess.PIPE,
                       check=True,
                       text=True,
                      )

我使用 stdout 来查看是否有输出。但是我真正想知道的是我是否可以访问我正在使用子进程打开的应用程序、软件或程序中的信息。

我只是想知道这是否可能,或者我是否应该使用另一种方法。

print('Standard Output:', p_run.stdout)
print('-------------')
print('Standard Error:', p_run.stderr)
print('-------------')
print('Arguments:', p_run.args)
print('-------------')
print('Return Code:', p_run.returncode)
print('-------------')
print('Check Return Code:', p_run.check_returncode)
print('-------------')
Standard Output: 
-------------
Standard Error: 
-------------
Arguments: ['open', '-n', '.../Applications (Parallels)/{c2916d26-d1f5-414d-b261-d6c91024400d} Applications.localized//Print 3D.app', '.../994012.stl']
-------------
Return Code: 0
-------------
Check Return Code: <bound method CompletedProcess.check_returncode of CompletedProcess(args=['open', '-n', '... Applications (Parallels)/{c2916d26-d1f5-414d-b261-d6c91024400d} Applications.localized//Print 3D.app', '...//994012.stl'], returncode=0, stdout='', stderr='')>
-------------

标签: pythonsubprocess

解决方案


推荐阅读