-1

I'm looking for a way to launch a compiled processing sketch from a function in python. It would just be a button programed with pygame (having a UI is very important.

can you launch an external file from within python?

2 Answers2

1

If you have your compiled jar you can use subprocess as show here:

import subprocess
subprocess.call(['java', '-jar', 'my-sketch.jar'])
Community
  • 1
  • 1
Marcos
  • 46
  • 1
  • 4
1

In order to launch an extern command using Python3 (or Python2), you can use one of those methods:

Example: i will call the bash function ls -l :

Method1:

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

Method2:

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

Bonus:

If you want to retrieve the output of the extern command you called, use this method:

Bonus method:

>>> output = subprocess.Popen("ls -l", shell = True, stdout=subprocess.PIPE)
>>> output
Chiheb Nexus
  • 9,104
  • 4
  • 30
  • 43