Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call Perl script from Python

Tags:

python

I've got a Perl script that I want to invoke from a Python script. I've been looking all over, and haven't been successful. I'm basically trying to call the Perl script sending 1 variable to it, but don't need the output of the Perl script, as it is a self contained program.

What I've come up with so far is:

var = "/some/file/path/"
pipe = subprocess.Popen(["./uireplace.pl", var], stdin=subprocess.PIPE)
pipe.stdin.write(var)
pipe.stdin.close()

Only just started Python programming, so I'm sure the above is total nonsense. Any help would be much appreciated.

like image 684
user574490 Avatar asked Jan 13 '11 15:01

user574490


People also ask

How do I call a Python script in LabVIEW?

Calling Perl and Python Scripts from LabVIEW In LabVIEW you can use the System Exec.vi to execute a system-level command line that can include any parameters supported by the application you want to launch. This VI can be used to call a command line argument that will launch the Perl or Python script.


2 Answers

Just do:

var = "/some/file/path/"
pipe = subprocess.Popen(["perl", "uireplace.pl", var])
like image 159
mouad Avatar answered Sep 21 '22 13:09

mouad


If you just want to open a pipe to a perl interpreter, you're on the right track. The only thing I think you're missing is that the perl script itself is not an executable. So you need to do this:

var = "/some/file/path/"
pipe = subprocess.Popen(["perl", "./uireplace.pl", var], stdin=subprocess.PIPE)
pipe.stdin.write(var)
pipe.stdin.close()
like image 37
Ken Kinder Avatar answered Sep 22 '22 13:09

Ken Kinder