Pros Terminal Frustrating to Popen

I am using popen to redirect the output of prosv5 terminal to a program that processes said output, which is a very long log that can only be transferred over the terminal. However, the following error keeps occurring:

RoboGod
Loading 832 event(s)....
2/832--- Logging error ---
Traceback (most recent call last):
  File "D:\a\1\s\pros\serial\terminal\terminal.py", line 236, in reader
  File "D:\a\1\s\pros\serial\terminal\terminal.py", line 45, in write
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\site-packages\colorama\ansitowin32.py", line 41, in write
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\site-packages\colorama\ansitowin32.py", line 162, in write
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\site-packages\colorama\ansitowin32.py", line 190, in write_and_convert
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\site-packages\colorama\ansitowin32.py", line 196, in write_plain_text
OSError: [Errno 22] Invalid argument

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\a\1\s\pros\common\ui\log.py", line 38, in emit
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\site-packages\click\utils.py", line 260, in echo
OSError: [Errno 22] Invalid argument
Call stack:
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\threading.py", line 930, in _bootstrap
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\threading.py", line 973, in _bootstrap_inner
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\site-packages\sentry_sdk\integrations\threading.py", line 67, in run
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\threading.py", line 910, in run
  File "D:\a\1\s\pros\serial\terminal\terminal.py", line 245, in reader
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\logging\__init__.py", line 1481, in exception
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\logging\__init__.py", line 1475, in error
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\logging\__init__.py", line 1589, in _log
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\logging\__init__.py", line 1599, in handle
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\site-packages\sentry_sdk\integrations\logging.py", line 86, in sentry_patched_callhandlers
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\logging\__init__.py", line 1661, in callHandlers
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\logging\__init__.py", line 952, in handle
  File "D:\a\1\s\pros\common\ui\log.py", line 40, in emit
Message: OSError(22, 'Invalid argument')
Arguments: ()
--- Logging error ---
Traceback (most recent call last):
  File "D:\a\1\s\pros\serial\terminal\terminal.py", line 236, in reader
  File "D:\a\1\s\pros\serial\terminal\terminal.py", line 45, in write
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\site-packages\colorama\ansitowin32.py", line 41, in write
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\site-packages\colorama\ansitowin32.py", line 162, in write
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\site-packages\colorama\ansitowin32.py", line 190, in write_and_convert
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\site-packages\colorama\ansitowin32.py", line 196, in write_plain_text
OSError: [Errno 22] Invalid argument

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\a\1\s\pros\common\ui\log.py", line 38, in emit
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\site-packages\click\utils.py", line 260, in echo
OSError: [Errno 22] Invalid argument
Call stack:
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\threading.py", line 930, in _bootstrap
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\threading.py", line 973, in _bootstrap_inner
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\site-packages\sentry_sdk\integrations\threading.py", line 67, in run
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\threading.py", line 910, in run
  File "D:\a\1\s\pros\serial\terminal\terminal.py", line 248, in reader
  File "D:\a\1\s\pros\serial\terminal\terminal.py", line 287, in stop
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\logging\__init__.py", line 1458, in warning
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\logging\__init__.py", line 1589, in _log
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\logging\__init__.py", line 1599, in handle
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\site-packages\sentry_sdk\integrations\logging.py", line 86, in sentry_patched_callhandlers
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\logging\__init__.py", line 1661, in callHandlers
  File "C:\hostedtoolcache\windows\Python\3.9.8\x64\lib\logging\__init__.py", line 952, in handle
  File "D:\a\1\s\pros\common\ui\log.py", line 40, in emit
Message: 'Stopping terminal'
Arguments: ()
Sentry is attempting to send 1 pending error messages
Waiting up to 2 seconds
Press Ctrl-Break to quit
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='cp1252'>
OSError: [Errno 22] Invalid argument

2 event(s) loaded from robot recorder.

The above errors stem from the stderr output of pros terminal. In addition, I do not have a micro sd card, and I’d rather not get one unless transferring the data over the terminal does not work out at all.

In essence, here is the “psuedocode”(it’s for a specially designed compiler) that captures the interactions. I’ll attach the transpiled c output, which is a PC program.

def loadEvents() array<event>:
	cdef popen(handle, handle) handle
	cdef pclose(handle) None
	cdef strerror(int) handle
	cdef puts(handle) None
	cdef sleep_ms(int) None
	cdef errno int
	
	terminal = popen(cmd="prosv5 terminal\0", mode="r\0")
	#terminal = popen(cmd="type testdata.txt\0", mode="r\0")
	if terminal == 0:
		puts(strerror(errno))
		abort "Cannot open pros terminal."
	
	reader = new io::reader(terminal)
	writer = io::output() #thats just how popen is - stdout is redirected as input into pros terminal
	
	if reader.consumeTillPhrase("ROBOGODAWK") == False:
		abort "Robogod never encountered ROBOGODAWK keyword!"
	reader.consumeWhitespace()
	events = new data::list<event>(reader.readInt(), new motorBrake(0, 0)) #motorBrake is a dummy event
	reader.consumeWhitespace()
	
	writer.write("Loading ")
	writer.write(events.buffer as int)
	writer.writeLine(" event(s)....")
	
	def loadEvent() nullable<event>:
		reader.consumeWhitespace()
		reader.readWhile(lambda char c: c != 'S' and c != 'M' and c != 'B' and c != 'R')
		if (eventType = reader.readChar()) == 'S': #stop loading events
			return None
		reader.consumeWhitespace()
		timeStamp = reader.readInt()
		reader.consumeWhitespace()
		magnitude = reader.readDec()
		reader.consumeWhitespace()
		velocity = reader.readInt()
		reader.consumeWhitespace()
		port = reader.readInt()
		reader.consumeWhitespace()
		
		if eventType == 'M': #motor move
			return new motorMove(port, magnitude, timeStamp)
		elif eventType == 'R': #motor move
			return new motorMoveRelative(port, magnitude, velocity, timeStamp)
		elif eventType == 'B': #motor brake
			return new motorBrake(port, timeStamp)
		else:
			cdef printf(handle, char, int, int) None
			printf(fmt = "Character is '%c', ASCII code is %i. Loaded %i events so far.\n", eventType, eventType, events.count)
			abort "Invalid event code recieved during transmission."
	
	while True:
		writer.write(events.count)
		writer.write('/')
		writer.write(events.buffer as int)
		match res=loadEvent():
			None:
				pclose(terminal)
				writer.writeLine('\r')
				return events.toArray()
			event e:
				events.pushBack(e)
				sleep_ms(450)
		writer.write('\r')

I’m pretty sure the code itself is working fine. It works when I run it against a similar program that simulates pros terminal.