简体   繁体   中英

How to pass python arguments to perl script?

I am writing a python script, from I am trying to call perl script. The input to the perl scripts are python arguments.

 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:

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. And since we avoid using a shell, we avoid having to build a shell command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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