【发布时间】:2015-10-05 04:13:18
【问题描述】:
我正在尝试使用模块 python cmd 编写一个 python CLI 程序。当我尝试在我的 CLI 程序中执行另一个 python 脚本时,我的目标是在其他文件夹中有一些 python 脚本,在其他文件夹中有 CLI 程序。我正在尝试使用 CLI 程序执行那些 python 脚本。
下面是用于执行其他脚本的os.popen方法还有CLI程序:
import cmd
import os
import sys
class demo(cmd.Cmd):
def do_shell(self,line,args):
"""hare is function to execute the other script"""
output = os.popen('xterm -hold -e python %s' % args).read()
output(sys.argv[1])
def do_quit(self,line):
return True
if __name__ == '__main__':
demo().cmdloop()
野兔是错误的:
(Cmd) shell demo-test.py
Traceback (most recent call last):
File "bemo.py", line 18, in <module>
demo().cmdloop()
File "/usr/lib/python2.7/cmd.py", line 142, in cmdloop
stop = self.onecmd(line)
File "/usr/lib/python2.7/cmd.py", line 221, in onecmd
return func(arg)
TypeError: do_shell() takes exactly 3 arguments (2 given)
有一些链接到其他 cmd CLI 程序 1 = cmd – Create line-oriented command processors 2 = Console built with Cmd object (Python recipe)
请在您的系统中运行上述代码。
【问题讨论】:
-
如果有人有想法。如何解决这个问题请发布你的程序..这对我的工作很有帮助
-
执行其他脚本,我也已经尝试过 sys.system() 如果你想用 os.system() 解决这个问题,请发布...
-
好的抱歉导入系统我在发布我的程序时删除它。
-
是的,在新的 xterm 中执行 python 脚本...你能帮帮我吗
标签: python python-2.7 subprocess ubuntu-14.04 python-os