我想在windows上运行一个批处理脚本通过python subprocess.call与piple。我有下面的列表,其中包含批处理脚本及其所有参数。
process_list [ 'batch_script.bat', 'arg1', 'arg2', 'arg3' ]现在我想使用下面的管道和grep命令来grep一些特定的行
above command|grep -iE 'abc|xyz'现在我还想把它写到一个文件或存储到一个变量中,我试着找到一些解决方案,比如stdout=subprocess.PIPE
pipe_var= ' | grep -iE \'abc|xyz\''
process_list.append(pipe_var)
subprocess.call(process_list, stdout=fo, shell=True) or this one
subprocess.call(process_list, stdout=subprocess.PIPE, shell=True)但它符合我的要求。你能帮帮忙吗?
发布于 2017-09-07 20:58:58
与此类似的东西:
import sys
sys.stdout = open('file.txt', 'w')
print 'this will now goto file.txt'https://stackoverflow.com/questions/46091313
复制相似问题