2

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.

2 Answers 2

5

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)
Sign up to request clarification or add additional context in comments.

3 Comments

Too easy. Thanks. I have to wait 8 more minutes before I can accept it.
One lingering question... When I run the perl script through command line, it executes the whole way through. When I do it through python, it hangs after the first line. Is there a simple solution to that?
never mind. I figured it out. I just changed it to stdout=subprocess.PIPE).communicate()
5

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.

Comments

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.