gpt4 book ai didi

python - 从 python 脚本中将参数传递给 x-executable 文件

转载 作者:太空宇宙 更新时间:2023-11-04 10:11:30 25 4
gpt4 key购买 nike

我正在尝试使用 python 脚本中的参数调用可执行文件(应用程序/x-可执行文件)。我看过类似的问题here但我仍然无法让它工作。通过终端调用此文件时,我只需使用以下形式:

location/of/file < output

意思是我用这两个参数调用函数。我正在尝试从我的 python 脚本中执行以下操作:

import subprocess

preprocess_path = "file_location"
subprocess.call([preprocess_path, '<', 'output.sas'])

但这似乎不起作用。有什么建议吗?任何帮助将不胜感激。

最佳答案

您应该能够使用 subprocess.Popen 并在打开输入文件的情况下使用关键字参数 stdin 来执行此操作:

import subprocess

preprocess_path = "file_location"

with open('output.sas', 'r') as f:
proc = subprocess.Popen([preprocess_path], stdin = f)
proc.wait()

关于python - 从 python 脚本中将参数传递给 x-executable 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48789467/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com