我正在尝试在子进程中使用unix diff命令,当我硬编码时,它工作正常,但我在一个函数中添加它,我需要将这些参数传递给diff。我该怎么做 ? 在下面的代码中,我有硬编码,但我想infile将file1.txt和outputfile作为file2.txt。
def file_comparison_2(infile,outputfile):
p = subprocess.Popen("diff file1.txt file2.txt",stdout=subprocess.PIPE, shell=True)
(output, err) = p.communicate()
FO = open("/users/home101/prabhus/python/pyunit-1.4.1/diff.txt", "wb")
print("Command output : ", output)
FO.write(output)
FO.close()
答案 0 :(得分:0)
p = subprocess.Popen("diff "+infile+" "+outfile,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
你可以这样做。