【问题标题】:launch processing sketch from python从 python 启动处理草图
【发布时间】:2016-11-08 15:00:53
【问题描述】:

我正在寻找一种从 python 中的函数启动编译处理草图的方法。它只是一个用 pygame 编程的按钮(有一个 UI 非常重要。

你能从 python 中启动一个外部文件吗?

【问题讨论】:

  • 为什么不使用subprocess.Popen

标签: python python-2.7 python-3.x pygame processing


【解决方案1】:

如果你有编译好的 jar,你可以使用 subprocess as show here:

import subprocess
subprocess.call(['java', '-jar', 'my-sketch.jar'])

【讨论】:

    【解决方案2】:

    要使用 Python3(或 Python2)启动 extern 命令,您可以使用以下方法之一:

    示例: 我将调用 bash 函数 ls -l

    方法一:

    >>> from subprocess import call
    >>> call(["ls","-l"]
    

    方法二:

    >>> from os import system
    >>> system("ls -l")
    

    奖励:

    如果您想检索您调用的 extern 命令的输出,请使用此方法:

    奖励方式:

    >>> output = subprocess.Popen("ls -l", shell = True, stdout=subprocess.PIPE)
    >>> output
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-24
      • 1970-01-01
      • 1970-01-01
      • 2014-04-03
      • 2021-02-28
      • 1970-01-01
      • 1970-01-01
      • 2012-12-16
      相关资源
      最近更新 更多