从python调用ksh脚本 [英] calling ksh script from python

查看:112
本文介绍了从python调用ksh脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正试图从python中调用ksh脚本。

我有一个带有scirpt的文件(toto.env)看起来像:


- 开始---

#!/ bin / ksh



导出TOTO_ENV = / home / toto

- 结束---


我这样从python中调用它:

- 开始---

导入命令

commands.getstatusoutput(''。toto.env'')

- 结束 - -


但它总是返回错误说:

sh:TOTO_ENV = / home / home:不是标识符

没有人知道为什么?

无论我用什么(popen,system ......)它总是一样的错误...

如果我直接尝试做

commands.getstatusoutput(''export TOTO_ENV = / home / toto'')

它是同样的错误...

和错误消息中的这个小问题怎么样,我不能使用ksh

脚本吗?


感谢任何帮助


ronan

hi all,

I''m trying to call ksh script from python.
I have a file (toto.env) with a scirpt looking like:

-- begin ---
#!/bin/ksh
#
export TOTO_ENV=/home/toto
-- end ---

I call it from python like that:
-- begin ---
import commands
commands.getstatusoutput(''. toto.env'')
-- end ---

but it always return an error saying:
sh: TOTO_ENV=/home/home: is not an identifier

doesn anyone know why ?
no matter what I use (popen,system...) it''s always the same error...
if I directly try to do
commands.getstatusoutput(''export TOTO_ENV=/home/toto'')
it''s the same error...
and what about this sh primpt in the error message, can''t I use ksh
script ?

thanks for any help

ronan

推荐答案

文章< 11 ******************* **@g14g2000cwa.googlegroups。 com>,
ro *********** @ yahoo.com 写道:

....
In article <11*********************@g14g2000cwa.googlegroups. com>,
ro***********@yahoo.com wrote:
....
我从python中调用它:
- 开始---
导入命令
commands.getstatusoutput(''。toto.env'')
- 结束---

但它总是返回错误说:
sh:TOTO_ENV = / home / home:不是标识符

没有人知道为什么?


....


和错误信息中的这个小问题怎么样,我不能用ksh
脚本?
I call it from python like that:
-- begin ---
import commands
commands.getstatusoutput(''. toto.env'')
-- end ---

but it always return an error saying:
sh: TOTO_ENV=/home/home: is not an identifier

doesn anyone know why ?
....

and what about this sh primpt in the error message, can''t I use ksh
script ?




是和否。你可以期待system(),popen()等。为了
调用标准的UNIX shell,sh,所以你必须提供

表达式,该表达式将由该shell正确执行。

该表达式可以执行用另一种

语言编写的程序 - 例如,''ksh toto.env''或''./toto.env''

如果你已经使它成为可执行文件并以#!/ bin / ksh开头。

这是调用脚本的最好方法。


同时,如果您对此事有任何选择,可能值得重新考虑使用这里的ksh b / b。 Ksh

适合交互使用,但有一些不幸的

缺陷作为编程外壳,并且由于专有问题

通常遇到一个另一种实施方式是'b
甚至更糟。在大多数现代平台上,sh将具有漂亮的优秀编程功能集,并且将更可靠

(特别是如果它不仅仅是另一个名称的ksh)。 )


Donn Cave, do**@u.washington.edu


在文章< do ************************ @ gnus01.u.washington.ed u> ;,

Donn Cave< do ** @ u.washington.edu>写道:
In article <do************************@gnus01.u.washington.ed u>,
Donn Cave <do**@u.washington.edu> wrote:


Cameron Laird写道:
Cameron Laird wrote:
Infidel。虽然我确实对csh(1)有这种感觉,但令我惊讶的是你会批评ksh(1)。 ''事实','mong
所有的* sh-s,我建议* ksh进行编程。 May-
让我们两个人以不同的方式看待事物。
Infidel. While I sure feel that way about csh(1), it
surprises me you''d criticize ksh(1) so. ''Fact, ''mong
all the *sh-s, I *recommend* ksh for programming. May-
be the two of us see things differently.




我一直想知道制造一个Python外壳是多么困难

暴露了所有Python,但也包括一些内置命令,例如

cd,mkdir等,它们只是绑定到os.chdir,os.mkdir ...和
非常聪明,可以从用户那里获取给定的命令,并尝试根据路径对其执行
os.system()。 IOW,我希望将所有的Python

作为我的unix shell使用,同时仍然使用shell类型的东西,例如

遍历目录,启动应用程序等。


可能有一个项目已经做到这一点,我只是不知道。


-

Paul McNett
http://paulmcnett.com



I keep wondering how difficult it would be to make a Python shell that
exposes all of Python but also includes some builtin commands such as
cd, mkdir, etc., that are just names bound to os.chdir, os.mkdir..., and
is smart enough to take a given command from the user and try to do a
os.system() on it based on the path. IOW, I''d love to have all of Python
available as my unix shell, while still doing shell-type stuff such as
traversing directories, launching applications, etc.

There''s likely a project that does this already that I''m just unaware of.

--
Paul McNett
http://paulmcnett.com


这篇关于从python调用ksh脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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