# Run a java Processing sketch with Python

**URL:** <https://discourse.processing.org/t/run-a-java-processing-sketch-with-python/40619>\
**Category:** Beginners\
**Created:** [January 17, 2023, 8:59am UTC](https://discourse.processing.org/t/run-a-java-processing-sketch-with-python/40619 "2023-01-17T08:59:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BBGiraffe](https://avatars.discourse-cdn.com/v4/letter/b/90db22/32.png) [@BBGiraffe](https://discourse.processing.org/u/BBGiraffe)\
**Post date:** [January 17, 2023, 8:59am UTC](https://discourse.processing.org/t/run-a-java-processing-sketch-with-python/40619/1 "2023-01-17T08:59:37Z")

</div>

Hi,

I want to use a python script run a processing sketch multiple time but with different args for each run.

I have processing sketch that works well if i run it manually via a cmd line eg “processing-java.exe --sketch=“path\to\sketch” --present ”

How would I write the .py script to trigger the sketch and pass it different args per iteration.  
Thx!

Note: I don’t need to convert the processing sketch to python I only want to trigger it to run with python.

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [January 17, 2023, 12:56pm UTC](https://discourse.processing.org/t/run-a-java-processing-sketch-with-python/40619/2 "2023-01-17T12:56:30Z")

</div>

Hi @BBGiraffe,

Presuming you know how to write a python script in general. So just use…

> **[subprocess — Subprocess management](https://docs.python.org/3/library/subprocess.html#subprocess.Popen)**
>
> Source code: Lib/subprocess.py The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace seve...

If you want it to unlink it from your main script just use  
`creationflags=subprocess.DETACHED_PROCESS`

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![BBGiraffe](https://avatars.discourse-cdn.com/v4/letter/b/90db22/32.png) [@BBGiraffe](https://discourse.processing.org/u/BBGiraffe)\
**Post date:** [January 22, 2023, 6:38am UTC](https://discourse.processing.org/t/run-a-java-processing-sketch-with-python/40619/3 "2023-01-22T06:38:09Z")

</div>

Thx: for more detail on how I resolved this:

```auto
command = f'processing-java.exe --sketch=E:\\path\\to\\processing\\folder --run'

def run_command(command):
    #run the command
    process = subprocess.Popen(command, shell=True, stderr=subprocess.PIPE)
    #capture the output
    output, error = process.communicate()
    #return the output
    return output

```
