今天在写一个python文件,其中想要去执行系统shell命令,在这条命令中,会用到pyhton变量,但是当我使用subprocess.Popen
()这个函数去执行的时候,会默认将变量当成一个字符串来使用,这就很尴尬了。
下面代码为我的处理办法:
lines = ff.readlines()
for line_code in lines:
line_new_code = line_code.strip('\n') //因为使用readlines函数,每行的最后面会读出/n,因此使用strip方法去掉
cpp = 'cp' + ' ' + line_new_code + ' ' + './xiaoma_suspect_sample' //将shell 命令拼接为一个字符串,在去整体执行
subprocess.Popen(cpp,shell = True)