[Tutor] subprocess figuring out what is in stdout
Nathan Smith
nathan-tech at hotmail.com
Mon May 16 22:05:12 EDT 2022
I'm working with a program which requires interactive shell like reading
of the output, EG user types input in response to various outputs
displayed to them.
Unfortunately, in some cases, the program being run is not either
printing an "\n" at the end of particular lines, or is not flushing it.
This only happens with specific points and is easily responsed.
Unfortunately, the unflushed data does not appear until the question
being asked is answered (rather unhelpful to the user)
My current implementation uses readline which is why I suspect the
problem may be that there is no "\n" character at the end, hence why
readline is not flushing it until more output is added.
One possible solution I found is to do stdout.read(1) and do it
character by character, but the efficiency seems low and this also
presents some other problems with other parts of my program.
To that end I was wondering, perhaps is there a way to tell how many
characters/bytes are in a stdout buffer before it is read? That way
read(x) could give the exact number.
I've seen some references talk about a way of making non blocking ports,
but these seem to be linux solutions and don't play nice with windows so
this doesn't really seem to be an option.
thanks in advance for any tips.
--
Best Wishes,
Nathan Smith, BSC
My Website: https://nathantech.net
More information about the Tutor
mailing list