user259861
user259861

Reputation: 87

run perl script with python

I've been looking at multiple examples on here and elsewhere, but nothing seems for work for me. I know nothing about python. All I am trying to do is run a perl script simply located at

sdb1/media/process.pl

The example code that I've found runs all over the place, and mostly seems like it has extra stuff that I don't need. What I'm trying right now is

#! /usr/bin/python
pipe = subprocess.Popen(["perl", "/sdb1/media/process.pl"], stdout=subprocess.PIPE)

But that just gives me the error

NameError: name 'subprocess' is not defined

If I've missed anything important, let me know. Otherwise, thanks for your time.

Upvotes: 2

Views: 5041

Answers (2)

CyanogenCX
CyanogenCX

Reputation: 404

Alternatively, if you are just using that same function a lot of times, you can do

from subprocess import Popen

then you can just call

pipe = Popen(["perl", "/sdb1/media/process.pl"], stdout=subprocess.PIPE)

I would have commented but I need 50 rep.

Upvotes: 5

smushi
smushi

Reputation: 719

you need to import the subprocess library to run subprocess

#! /usr/bin/python

import subprocess

pipe = subprocess.Popen(["perl", "/sdb1/media/process.pl"], stdout=subprocess.PIPE)

Upvotes: 5

Related Questions