【问题标题】:passing arguments to x-executable file from within a python script从 python 脚本中将参数传递给 x 可执行文件
【发布时间】:2018-02-14 14:23:17
【问题描述】:

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

location/of/file < output

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

import subprocess

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

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

【问题讨论】:

  • 尝试使用 Popen 代替 call
  • 我发现使用 ./filename.output 在项目中调用文件总是一个好习惯

标签: python linux subprocess


【解决方案1】:

您应该能够使用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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-21
    相关资源
    最近更新 更多