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

标签 python linux subprocess

我正在尝试使用 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/

相关文章:

python - 如何从python中的不同文件夹导入类?

python - ajax post 上的 django-csrf 保护

python - Subprocess.Popen 将子进程 stdout,stderr 路由到父进程

python - Popen 通讯无法正常工作

linux - 从 shell 脚本锁定 ubuntu

python - 捕获 python 子进程的输出

python - 如何在 .txt 文件中的 JSON 对象之间添加逗号,然后在 Python 中将其转换为 JSON 数组

python - 对 Panda Dataframe 中的一系列列表进行分组

linux - 无法生成 cscope.out 文件

php - 如何让服务器从另一个目录加载php?