# How can I get/fetch a response from invoked (launch() ) command?

**URL:** <https://discourse.processing.org/t/how-can-i-get-fetch-a-response-from-invoked-launch-command/43511>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [December 19, 2023, 9:55am UTC](https://discourse.processing.org/t/how-can-i-get-fetch-a-response-from-invoked-launch-command/43511 "2023-12-19T09:55:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bask185](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@bask185](https://discourse.processing.org/u/bask185)\
**Post date:** [December 19, 2023, 9:55am UTC](https://discourse.processing.org/t/how-can-i-get-fetch-a-response-from-invoked-launch-command/43511/1 "2023-12-19T09:55:33Z")

</div>

I used `launch()` to invoke a batch script. The batch script would than launch Arduino-cli to build and upload an arduino program to a board.

That was this fine working line.  
`launch("rundll32 SHELL32.DLL,ShellExec_RunDLL " + sketchPath("") +"\\flashArduino.bat") ; `

In order to get the correct COM port as well as board model. I would like to fetch the output generated by arduino-cli. This allow me to use the `board list` command to figure out which COM port I should use. The native `processing's Serial.list()` is not satisfactory:

```auto
[0] "CNCA2"
[1] "CNCB2"
[2] "COM4" 
[3] "COM7" 
[4] "COM8" 
[5] "COM9" 

```

So my question, how can I launch arduino-cli and fetch it’s respons from within a processing sketch?

```auto
launch("arduino-cli upload arduinoProgram -b arduino:avr:uno -p COM4") ;

```

I tried the above line for an upload, but the upload does not happen. The line itself works fine when running from a batch terminal.

Kind regards,

Bas

---

<div class="post-metadata">

**Author:** ![bask185](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@bask185](https://discourse.processing.org/u/bask185)\
**Post date:** [December 19, 2023, 11:45am UTC](https://discourse.processing.org/t/how-can-i-get-fetch-a-response-from-invoked-launch-command/43511/2 "2023-12-19T11:45:53Z")

</div>

I learned that I need to use the BufferReader class in combination with the InputStreamReader class. One must import the appropiate modules doe this.

```auto
void flashProgram()
{
    String myPath = sketchPath() ;
    String boardName ;
    String COM_PORT ;
    String command ;
    String line ;
    String jsonData = "";

    String arduinoCliPath = myPath + "\\Arduino-cli\\arduino-cli.exe " ;
    String sketchPath = myPath + "arduinoProgram" ;
    String listCommand = "board list --format json" ;

    try
    {
        command = arduinoCliPath + listCommand ;
        Process p = launch(command);
        BufferedReader in = new BufferedReader(new InputStreamReader( p.getInputStream()));

```

This succesfully launches arduino-cli and fetches the data that arduino-cli produces.

---

<div class="post-metadata">

**Author:** ![RichardDL](https://avatars.discourse-cdn.com/v4/letter/r/f475e1/32.png) [@RichardDL](https://discourse.processing.org/u/RichardDL)\
**Post date:** [December 23, 2023, 10:25pm UTC](https://discourse.processing.org/t/how-can-i-get-fetch-a-response-from-invoked-launch-command/43511/3 "2023-12-23T22:25:10Z")

</div>

@bask185, Very nice and useful. Was the code in post 2 meant to be a complete working sketch? I think it’s truncated.

---

<div class="post-metadata">

**Author:** ![bask185](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@bask185](https://discourse.processing.org/u/bask185)\
**Post date:** [December 27, 2023, 8:25pm UTC](https://discourse.processing.org/t/how-can-i-get-fetch-a-response-from-invoked-launch-command/43511/4 "2023-12-27T20:25:18Z")

</div>

No the code was just the relevant snippet. I use several files and my main is often big so posting complete programs in something other than a zip file is not really doable
