简体   繁体   中英

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.

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM