ProcessBuilder getInputStream seems to hold up 'Project Update' events

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

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))

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) and only upon a succesful process exit attempt to read the process' input stream.

1 Like

I'll remove once I'm done debugging permissions and runtime errors (though a comment may want to be added to this post 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.

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)

1 Like

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.

Tried to just read the first 100 bytes and it still locked up and output nothing. :frowning: 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.