0

I am trying to run the Perl script rtpc.pl from a Python script from the command line with two input arguments. Normally, I run the Perl script from the command line with two arguments:

perl rtpc.pl [ARG1] [ARG2]

What I want is a separate python script that I can call from the command line that I can input [ARG1] and [ARG2] into while compiling the Perl script rtpc.pl.

Something like:

python3 pyscript.py 

So far, in my python script, I am using the subprocess module, but I am a little unsure how to pass arguments for my perl script.

pipe = subprocess.Popen(["perl", "rtpc.pl"], stdout=subprocess.PIPE)

How would I input the arguments needed to equivalently run the Perl script terminal command? I should also mention that the shell that I am using is tcsh.

1
  • In python 3.5+ you want subprocess.run. The Popen is an "underlying interface" recommended for "more advanced" needs Commented Aug 19, 2022 at 1:21

1 Answer 1

1

Add them to the list you pass to subprocess.Popen().

arg1 = 'foo'
arg2 = 'bar'
pipe = subprocess.Popen(["perl", "rtpc.pl", arg1, arg2], stdout=subprocess.PIPE)
Sign up to request clarification or add additional context in comments.

3 Comments

Do the arguments have to be encased in quotes? And can I pass integers?
You're starting a subprocess. That's done by passing a finite number of strings to a program. That's nothing specific to Python; that's how processes work at a fundamental level.
@Austin The arguments are all strings. You can convert integers with str(variable).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.