Reputation: 1
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
Upvotes: 0
Views: 283
Reputation: 386676
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.
Upvotes: 2