# ProcessBuilder getInputStream seems to hold up 'Project Update' events

**URL:** <https://forum.inductiveautomation.com/t/processbuilder-getinputstream-seems-to-hold-up-project-update-events/76016>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [July 6, 2023, 6:30pm UTC](https://forum.inductiveautomation.com/t/processbuilder-getinputstream-seems-to-hold-up-project-update-events/76016 "2023-07-06T18:30:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [July 6, 2023, 6:30pm UTC](https://forum.inductiveautomation.com/t/processbuilder-getinputstream-seems-to-hold-up-project-update-events/76016/1 "2023-07-06T18:30:15Z")

</div>

Trying to setup a script to automatically commit to git when a project updates based on the example IA provided in their gitlab documentation. Switched from system.util.execute() since I was having some mystery error in the background which had me fighting with git permissions(had to add the project to the safe.directory). I went to try to run the bat file again, but now it seems like my script is getting stuck on the Input or Error strings(tried both ways).

Any ideas what is occurring? Nothing in the wrapper logs, and the only way to get the event to fire again is to reboot the gateway to my knowledge.

Edit: Version 8.1.20

```auto
import GitLibrary
from java.lang import ProcessBuilder, String

logger = system.util.getLogger('UpdateScript')

GitLibrary.exportTagsToProjectFolder()
GitLibrary.exportImagesToProjectFolder('')
builder = ProcessBuilder([r"cmd.exe", r"C:\\Program Files\\Inductive Automation\\Ignition\\data\\git-auto-commit.bat"])
process = builder.start()

output = String(process.getInputStream().readAllBytes())

logger.warn('update attempted: ' + str(output))
```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 6, 2023, 6:52pm UTC](https://forum.inductiveautomation.com/t/processbuilder-getinputstream-seems-to-hold-up-project-update-events/76016/2 "2023-07-06T18:52:01Z")

</div>

> [@grietveld](#):
>
> `String(process.getInputStream().readAllBytes())`

That's really dangerous, because the process might not ever complete (for instance, what if it's waiting on input?) and therefore you're stuck waiting forever.

You should launch the process, wait a select amount of time (using [`waitFor`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Process.html#waitFor(long,java.util.concurrent.TimeUnit))) and only upon a succesful process exit attempt to read the process' input stream.

---

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [July 6, 2023, 6:56pm UTC](https://forum.inductiveautomation.com/t/processbuilder-getinputstream-seems-to-hold-up-project-update-events/76016/3 "2023-07-06T18:56:48Z")

</div>

I'll remove once I'm done debugging permissions and runtime errors (though a comment may want to be added to [this post](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/16) then since it was my reference).

Any ideas or ways to debug why it isn't getting anything anymore? bat file will execute fine on its own at least.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [July 6, 2023, 6:59pm UTC](https://forum.inductiveautomation.com/t/processbuilder-getinputstream-seems-to-hold-up-project-update-events/76016/4 "2023-07-06T18:59:50Z")

</div>

Instead of `readAllBytes()` on the input stream, you could try reading chunks of bytes and emitting them from your logger:  
[https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/InputStream.html#readNBytes(int)](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/InputStream.html#readNBytes(int))

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [July 6, 2023, 7:08pm UTC](https://forum.inductiveautomation.com/t/processbuilder-getinputstream-seems-to-hold-up-project-update-events/76016/5 "2023-07-06T19:08:38Z")

</div>

Using `.readAllBytes()` is dangerous unless you are using it on both the process's stdout and stderr streams **in parallel**. If not, OS buffers can block the process on one stream while you are trying to read everything from the other.

---

<div class="post-metadata">

**Author:** ![grietveld](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/grietveld/32/6984_2.png) [@grietveld](https://forum.inductiveautomation.com/u/grietveld)\
**Post date:** [July 6, 2023, 7:28pm UTC](https://forum.inductiveautomation.com/t/processbuilder-getinputstream-seems-to-hold-up-project-update-events/76016/6 "2023-07-06T19:28:58Z")

</div>

Tried to just read the first 100 bytes and it still locked up and output nothing. ☹ Been fighting this for a while, so think I'm gonna take a break for the night and pick up tomorrow with fresh eyes. It was working fine, so hopefully I can find whatever error I created while debugging and updating git configurations.

---

<div class="post-metadata">

**Author:** ![Martin\_Horak](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@Martin\_Horak](https://forum.inductiveautomation.com/u/Martin_Horak)\
**Post date:** [October 25, 2024, 1:37pm UTC](https://forum.inductiveautomation.com/t/processbuilder-getinputstream-seems-to-hold-up-project-update-events/76016/7 "2024-10-25T13:37:03Z")

</div>

This might be useful [Handling blocked Process output stream - Don't Panic!](https://www.dontpanicblog.co.uk/2023/05/07/handling-blocked-process-output-stream/)  
Reading the input stream without separate thread, there is always chance it will be stuck.
