简体   繁体   English

如何将python参数传递给perl脚本?

[英]How to pass python arguments to perl script?

I am writing a python script, from I am trying to call perl script.我正在编写一个 python 脚本,因为我试图调用 perl 脚本。 The input to the perl scripts are python arguments. perl 脚本的输入是 python 参数。

 row[i[k]]=re.sub(r"^_", "", row[i[k]])
 row[i[k]]=re.sub(r"{", "[", row[i[k]])
 row[i[k]]=re.sub(r"}", "]", row[i[k]])
 row[i[0]]=re.sub(r"^_", "", row[i[0]])
 row[i[0]]=re.sub(r"{", "[", row[i[0]])
 row[i[0]]=re.sub(r"}", "]", row[i[0]])
 cmd = "perl process_str.pl -str1 "row[i[0]]" -str2 "row[i[k]]""
 os.system(cmd)

But I'm seeing following error on running the python script:但是我在运行 python 脚本时看到以下错误:

cmd = "perl process_str.pl -str1 "row[i[0]]" -str2 "row[i[k]]""
                                ^
SyntaxError: invalid syntax

The following can be used:可以使用以下内容:

subprocess.call([ "perl", "process_str.pl", "-str1", row[i[0]], "-str2", row[i[k]] ])

There's no point invoking a shell to launch perl when we can launch perl directly.有没有点调用shell来启动perl时候我们可以启动perl直接。 And since we avoid using a shell, we avoid having to build a shell command.由于我们避免使用 shell,我们避免了必须构建 shell 命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM