Python子流程中的Awk无法正常运行

时间:2018-06-27 16:34:53

标签: python awk subprocess

我正在尝试运行:

p3 = subprocess.Popen('awk \'{ print $6 "\t" $1 "\t" $2 "\t" $3 "\t" $4 "\t" $5 }\''.split(' '), stdin=p3.stdout, stdout=f)

但收到错误:

awk: syntax error at source line 1
 context is
     >>> ' <<< 
    missing }
awk: bailing out at source line 1

以前有人遇到过这个问题吗?

1 个答案:

答案 0 :(得分:0)

我建议您在寻找:

cmd = ['awk', '-v', 'OFS="\t"', '{print $6, $1, $2, $3, $4, $5}']
p = subprocess.Popen(cmd, stdin=[what are you reading from?], stdout=subprocess.PIPE)
result = p.stdout.read().split(' ')