我正在嘗試使用模塊python cmd編寫一個python CLI程序。當我嘗試在我的CLI程序中執行另一個python腳本時,我的目標是在其他文件夾中的其他文件夾和CLI程序中有一些python腳本。我正在嘗試使用CLI程序來執行這些python腳本。os.popen如何使用參數externaly來運行另一個腳本
下面是用於執行其他有腳本的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命令行程序 1 = cmd – Create line-oriented command processors 2 = Console built with Cmd object (Python recipe)
請在您的系統中運行上面的代碼。
如果任何人都可以有想法。如何解決這個請發佈你的程序..這是非常有助於我的工作 –
執行其他腳本,我也已經嘗試sys.system()如果你有想法解決這個與os.system()請發佈。 .. –
確定對不起導入系統我是刪除這個時候發佈我的程序。 –