Reputation: 17
I have written this code to run a Perl script from my Python script:
#!/usr/bin/python
import subprocess
var = "/some/file/path/"
pipe = subprocess.Popen(["perl", "./SignalPktSender.pl ", var], stdin=subprocess.PIPE)
But my perl script needs command line arguments. How can I pass command arguments to the Perl script when it is run from my Python script?
Upvotes: 0
Views: 2335
Reputation: 2493
From the Python docs on the subprocess module:
class subprocess.Popen(args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0)
Arguments are:
args should be a string, or a sequence of program arguments. The program to execute is normally the first item in the args sequence or the string if a string is given, but can be explicitly set by using the executable argument.
Your code so far is:
pipe = subprocess.Popen(["perl", "./SignalPktSender.pl ", var], stdin=subprocess.PIPE)
which has a list at the start of the arguments you're sending, and it looks like you're already passing a command line argument (var
) - just add your other command line arguments to the list after var
.
Upvotes: 1