简体   繁体   English

用python运行perl脚本

[英]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. 我对python一无所知。 All I am trying to do is run a perl script simply located at 我所要做的就是运行一个简单的perl脚本

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. 我会评论但我需要50个代表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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