【发布时间】:2014-08-29 02:31:13
【问题描述】:
假设我有一个命令,该命令将文件路径作为输入并编译该文件。 我想使用 subprocess 从 python 脚本调用此命令。
使用 python,我提取了文件内容并对其进行了修改,我想编译它。 我不需要存储我要编译的新文件内容。
问题是:
有没有办法(例如子进程中的方法)编译文件内容而无需手动写入然后在文件系统中删除?
【问题讨论】:
标签: python subprocess
假设我有一个命令,该命令将文件路径作为输入并编译该文件。 我想使用 subprocess 从 python 脚本调用此命令。
使用 python,我提取了文件内容并对其进行了修改,我想编译它。 我不需要存储我要编译的新文件内容。
问题是:
有没有办法(例如子进程中的方法)编译文件内容而无需手动写入然后在文件系统中删除?
【问题讨论】:
标签: python subprocess
您可以在语法中给出编译/运行命令。
此外,提供带有完整路径的可执行文件/文件名。
P = subprocess.Popen(['your_run_command','filename_with_path', 'any_extra_parameter_you_want_to_add'], STDIN=subprocess.PIPE,STDOUT=subprocess.PIPE,stderr=subprocess.PIPE)
output,err = P.communicate()
P.wait()
#For removing the already existing file
if os.path.exists('filename_with_path'):
os.remove('filename_with_path')
【讨论】:
f 是我的文件f.write(filename)