在python 2.4中,如何使用csh而不是bash执行外部命令? [英] In python 2.4, how can I execute external commands with csh instead of bash?

查看:146
本文介绍了在python 2.4中,如何使用csh而不是bash执行外部命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不使用新的2.6子过程模块,如何使用tcsh而不是bash使os.popen或os.system执行命令?在执行其他命令之前,我需要获取一些用tcsh编写的脚本,而我需要在python2.4中执行此操作。

Without using the new 2.6 subprocess module, how can I get either os.popen or os.system to execute my commands using the tcsh instead of bash? I need to source some scripts which are written in tcsh before executing some other commands and I need to do this within python2.4.

EDIT
感谢您的答复使用'tcsh -c',但我想避免这种情况,因为我必须逃避疯狂。该字符串将由bash解释,然后由tcsh解释。我将必须执行以下操作:

EDIT Thanks for answers using 'tcsh -c', but I'd like to avoid this because I have to do escape madness. The string will be interpreted by bash and then interpreted by tcsh. I'll have to do something like:

os.system("tcsh -c '"+re.compile("'").sub(r"""'"'"'""",my_cmd)+"'")

我不能只告诉python打开一个'tcsh'子进程而不是一个'bash'子进程吗?

Can't I just tell python to open up a 'tcsh' sub-process instead of a 'bash' subprocess? Is that possible?

P.S。
我意识到bash是猫的喵,但是我在公司环境中工作,我会选择打tcsh vs bash的战斗-炸更大的鱼

P.S. I realize that bash is the cat's meow, but I'm working in a corporate environment and I'm going to choose to not fight a tcsh vs bash battle -- bigger fish to fry.

推荐答案

只需在命令前添加shell前缀即可。我没有安装tcsh,但安装了zsh:

Just prefix the shell as part of your command. I don't have tcsh installed but with zsh:

>>> os.system ("zsh -c 'echo $0'")
zsh
0

这篇关于在python 2.4中,如何使用csh而不是bash执行外部命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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