aki2all
aki2all

Reputation: 427

Cannot capture single quote string in Python from Perl

I have a Perl script from which I am calling a Python script.

I am using:

system "python script.py '".$var1."' '".$var2."' '".$var3."' '".$var4."' '".$var5."'";

Where, $var1 = "'Nostoc azollae' 0708", which has single quotes in the string.

In the script.py script, I am using:

var1 = sys.argv[1]

And if I print var1, it only prints: Nostoc and the rest is not printed, rest is working fine.

So, clearly the Python script is not receiving the string with the ' included.

What can be a solution to this?

Upvotes: 1

Views: 59

Answers (1)

mpapec
mpapec

Reputation: 50647

Avoid shell invocation when using system() by using separate parameters instead of joining them all together,

system("python", "script.py", $var1, $var2, $var3, $var4, $var5);

Upvotes: 3

Related Questions