簡體   English   中英

在正在運行的python腳本中運行命令

[英]Run a command inside a running python script

我認為這是一件非常容易的事,但我仍在尋找答案。

我正在運行一個如下所示的Python腳本:

等待爭論:_________

有一種簡單的方法可以啟動腳本並自動在其中添加一些參數嗎?

我真的不明白你,但我想你想要這樣的東西

import os, sys 
#def some_other_functions
def cmd():
 try:
  com = raw_input('Waiting for argument:_________  ')
  #Or u can pass values as sys.args
  #like com = sys.argv[1]
  while len(com) == 0:
   com = raw_input('Waiting for argument:_________  ')
   if len(com) != 0:
     print os.system(com)
   if str(com) == 'exit':
      sys.exit()
   print '\nContinuer executing other commands or write --exit to quite the program\n'
   while True:
     com = raw_input('Waiting for argument:_________  ')
   if len(com) == 0:
     print 'Entered nothing'
   if str(com) == 'exit':
     sys.exit()
   else:
     print os.system(com)
 except Exception, e:
   print str(e)
cmd()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM