我想通过python subprocess.call windows在Windows上运行批处理脚本。我有以下列表,其中包含带有所有参数的批处理脚本。
process_list [ 'batch_script.bat', 'arg1', 'arg2', 'arg3' ]
现在,我想使用以下管道和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)
,但它与我的要求符合。你能帮忙吗?
有一个重定向的stdout函数
与此接近的东西:
import sys
sys.stdout = open('file.txt', 'w')
print 'this will now goto file.txt'