【问题标题】:Making a process wait for command让进程等待命令
【发布时间】:2014-05-23 20:32:26
【问题描述】:

我正在制作一个程序来执行我在 linux 中输入的命令。例如:

~> Python myProgram 启动
~> cd Music(或其他一些 linux 命令)
~/Music> Python myProgram doSomething
~/音乐> cd ..
~>Python myProgram doSomethingElse

我猜这个程序应该是这样的:

if sys.argv == "start":
  get processID
  echo processID >> /dev/shm/ID
  while True:
    wait for command
    method(argument)
if sys.argv == "doSomething":
  processID = read("/dev/shm/ID")
  tell process to run method(doSomething)

def Method()
def read()

我的问题是:我从哪里开始?我必须使用 Thread、Multiprocessing、Subprocess 还是 Popen?
任何帮助表示赞赏!

【问题讨论】:

  • def Method()def read() 是什么?
  • 对我来说,您似乎需要subprocess,尽管我不了解您更换终端的用例...使用readlinepexpect 可能有更奇特的方式。

标签: python unix process


【解决方案1】:

这是一个用python创建命令行工具的近界面,这可能是一个很好的起点https://docs.python.org/2/library/cmd.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-13
    • 2014-12-26
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 2016-01-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多