在 subprocess.Popen 调用 awk 中转义两种类型的引号 [英] Escaping both types of quotes in subprocess.Popen call to awk

查看:43
本文介绍了在 subprocess.Popen 调用 awk 中转义两种类型的引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的子进程调用应该调用 tabix 1kg.phase1.snp.bed.gz -B test.bed |awk '{FS="\t";OFS="\t"} $4 >= 10' 但给我错误,因为它同时具有 "' 在其中.我尝试将 r 用于原始字符串,但我无法找出正确的组合来防止错误.我当前的调用如下:

My subprocess call should be calling tabix 1kg.phase1.snp.bed.gz -B test.bed | awk '{FS="\t";OFS="\t"} $4 >= 10' but is giving me errors because it has both " and ' in it. I have tried using r for a raw string but I can't figure out the right combination to prevent errors. My current call looks like:

snp_tabix = subprocess.Popen(["tabix", tgp_snp, "-B", infile, "|", "awk", """'{FS="\t";OFS="\t"}""", "$4", ">=", maf_cut_off, r"'"], stdout=subprocess.PIPE)

哪个给出了错误 TypeError: execv() arg 2 must contain only strings

推荐答案

r"'" 不是问题.很可能您将 maf_cut_off 作为整数传递,这是不正确的.你应该使用 str(maf_cut_off).

r"'" is not the issue. Most likely you're passing maf_cut_off as an integer, which is incorrect. You should use str(maf_cut_off).

这篇关于在 subprocess.Popen 调用 awk 中转义两种类型的引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆