Running a perl script within a python script is giving qoutes issues

I am trying to execute a perl script from within a python script like this:

cmd = ‘perl mydrive/test.pl . " + “"” + str(value) + ""’
Running this perl script should take the value with qoutes and updates a bunch of other files with this qouted value.

But whenever I see the files being updated, the value that shows up in the updated file is value and not “value”, any idea what I am doing wrong here?

Are you executing this with subprocess? On what system? What would be the exact perl command line that would work in the console? Put between triple backtick lines.

```
perl <arguments>
```

With subprocess, you might do better to give the command as a list rather than a string. Read the discussion about args.

Yes, I am trying to execute this with subprocess.

@tjreedy You mean use something like this:

arguments = '''"{}"'''.format(value)
    command = '''perl mydrive/test.pl . ''' + arguments

What I meant is to start with the exact line you would enter into CommandPrompt or PowerShell or bash or Terminal, then work out, using the link I gave, how to encode/quote it in a subprocess call so that the needed line gets delivered to the system shell. The ‘shell=True’ subprocess argument may affect this.

You don’t need to construct a shell pipeline in order to execute perl, which means you don’t have to worry about shell quoting rules.

Construct a list containing the command and its arguments as separate elements, instead of a string that the shell would parse into such a list. I assume you type in the shell

perl mydrive/test.pl . "some value"

In Python, if you already have

value = "some value"

then you can use a list like the following to execute the same command.

cmd = ['perl', 'mydrive/test.pl', '.', value]
subprocess.run(cmd)