使用Python运行其他程序 [英] using Python to run other programs

查看:101
本文介绍了使用Python运行其他程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是程序员所以我有一个非常愚蠢的问题。我正在努力

制作一个实用的剧本。我需要在其中运行一个可执行程序,但是我不能让它工作。也许有人可以轻松搞清楚:


-----

#! / python


a =(收件人的电子邮件地址)


pgp -feat a


(加密后发送邮件到地址)

------


如何让python打开pgp程序?


我应该使用python以外的环境吗?


谢谢!

Hi, i''m not a programmer so I have a very stupid question. I''m trying to
make a practical script. I need to run an executable program in it but i
can''t get it to work. Maybe someone here can figure it out easily:

-----
#! /python

a = (recipient''s e-mail address)

pgp -feat a

(sendmail to address after encryption)
------

How do I get python to open the pgp program?

Should I use an environment other than python?

thanks!

推荐答案



使用python来运行shell命令非常简单。

你需要做的就是创建你想要运行的命令行。在您的

案例中:

command =" pgp -feat" + a

然后使用os.system()运行它,如下所示:

import os

os.system(command)

如果你还想获得命令的输出,你可以使用

''命令''模块,如下所示:

import命令


输出,rc = commands.getoutput(命令)


然后你得到输出到变量''output'',并且将

程序的代码退出到变量''rc''。


sagiv。

" Frog" <星期五********** @ bigfoot.com>在消息中写道

news:7T ********************** @ Gilgamesh-frog.org ...

using python to run shell commands is very easy.
all you need to do is create the command line you would want to run. in your
case:
command = "pgp -feat " + a
and then run it using os.system(), like this:
import os
os.system(command)
if you also want to get the output of the command, you can use the
''commands'' module, like this:
import commands

output, rc = commands.getoutput(command)

then you get the output into the variable ''output'', and the exit code of the
program into the variable ''rc''.

sagiv.
"Frog" <Fr**********@bigfoot.com> wrote in message
news:7T**********************@Gilgamesh-frog.org...
我不是程序员所以我有一个非常愚蠢的问题。我正在努力制作一个实用的剧本。我需要在其中运行一个可执行程序,但我无法让它工作。也许有人可以轻松搞清楚:

-----
#! / python
a =(收件人的电子邮件地址)

pgp -feat a

(加密后发送邮件到地址)
------

如何让python打开pgp程序?

我应该使用python以外的环境吗?
<谢谢!
Hi, i''m not a programmer so I have a very stupid question. I''m trying to
make a practical script. I need to run an executable program in it but i
can''t get it to work. Maybe someone here can figure it out easily:

-----
#! /python

a = (recipient''s e-mail address)

pgp -feat a

(sendmail to address after encryption)
------

How do I get python to open the pgp program?

Should I use an environment other than python?

thanks!



下载Duplicity,里面有一个不错的GnuPG模块,也可以是

演示了如何实现这一目标的技术。

http:/ /www.nongnu.org/duplicity

使用标准库发送电子邮件非常简单。看看你的Python安装附带的教程




Best,
$ b $bMiklós


Frog< Fr ********** @ bigfoot.com>在消息中写道

news:7T ********************** @ Gilgamesh-frog.org ...
Download Duplicity, there''s a nice GnuPG module in it, which would also
demonstrate the technique how this can be done.

http://www.nongnu.org/duplicity

To send e-mail is pretty easy by using the standard library. Have a look at
the tutorial which comes with your Python installation.

Best,
Miklós

Frog <Fr**********@bigfoot.com> wrote in message
news:7T**********************@Gilgamesh-frog.org...
我不是程序员所以我有一个非常愚蠢的问题。我正在努力制作一个实用的剧本。我需要在其中运行一个可执行程序,但我无法让它工作。也许有人可以轻松搞清楚:

-----
#! / python
a =(收件人的电子邮件地址)

pgp -feat a

(加密后发送邮件到地址)
------

如何让python打开pgp程序?

我应该使用python以外的环境吗?
<谢谢!
Hi, i''m not a programmer so I have a very stupid question. I''m trying to
make a practical script. I need to run an executable program in it but i
can''t get it to work. Maybe someone here can figure it out easily:

-----
#! /python

a = (recipient''s e-mail address)

pgp -feat a

(sendmail to address after encryption)
------

How do I get python to open the pgp program?

Should I use an environment other than python?

thanks!



这是我第三次下载,安装和试用过Boa。每一次我都会遇到一个或另一个挫折。这次我试图通过

入门,并找到许多地方,教程不同意

与现实或我尝试的东西,它确实不工作。


有没有人在Boa Constructor上取得成功?如果是这样你是如何学习它的?

教程显然不是我学习它的方式。


Bob Gailer
bg ***** @ alum.rpi.edu

303 442 2625

---

外发邮件经过无病毒认证。

由AVG反病毒系统检查( http://www.grisoft.com)

版本:6.0.538 /病毒数据库:333 - 发布日期: 11/10/2003

This is the 3rd time I''ve downloaded, installed and tried Boa. Each time I
meet with one frustration or another. This time I''m trying to go thru the
Getting Started, and find numerous places that the tutorial does not agree
with the reality or I try something and it does not work.

Has anyone had success with Boa Constructor? If so how did you learn it?
The tutorial clearly is not the way I can learn it.

Bob Gailer
bg*****@alum.rpi.edu
303 442 2625
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.538 / Virus Database: 333 - Release Date: 11/10/2003


这篇关于使用Python运行其他程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆