Unable to read program stdout when running.

Discuss emulation or program issues here.
Post Reply
User avatar
gamax92
Posts: 22
Joined: Mon Oct 28, 2013 2:07 pm

Unable to read program stdout when running.

Post by gamax92 » Mon Oct 28, 2013 8:27 pm

I know this seems like an odd issue, but I was doing some experimental tests with the program itself, and was running into an issue.

I'm using the WScript method to Execute cen64 and then attempting to get the StdOut of it.
This works, unless cen64 actually gets started simulating an n64, when that happens, the ReadLine/Read/ReadAll completely stops the program until cen64 is closed.
If I use something like DIR and read every line, I can get the output while the program is running.
If cen64 gives an error or its usage info, it also reads the lines just fine.

I know, it seems like I'm just complaining over something irrelevant, and yes it doesn't matter at all. Just wondering if you knew why I'm unable to do this.

If you want, I can post the code to my program.

User avatar
MarathonMan
Site Admin
Posts: 692
Joined: Fri Oct 04, 2013 4:49 pm

Re: Unable to read program stdout when running.

Post by MarathonMan » Mon Oct 28, 2013 8:36 pm

It prints to StdErr, not StdOut.

On Linux, I have to redirect using

Code: Select all

./cen64 ... 2>&1 ...

User avatar
gamax92
Posts: 22
Joined: Mon Oct 28, 2013 2:07 pm

Re: Unable to read program stdout when running.

Post by gamax92 » Mon Oct 28, 2013 9:10 pm

For me it is printing to StdOut, as when I changed the code to read from StdErr, I got nothing at all, even at program close. Atleast on StdOut I got the output when the program closed.
I also tried what you mentioned about redirecting stderr to stdout but still it seems to sit there until the program closes.

User avatar
MarathonMan
Site Admin
Posts: 692
Joined: Fri Oct 04, 2013 4:49 pm

Re: Unable to read program stdout when running.

Post by MarathonMan » Mon Oct 28, 2013 9:31 pm

gamax92 wrote:For me it is printing to StdOut, as when I changed the code to read from StdErr, I got nothing at all, even at program close. Atleast on StdOut I got the output when the program closed.
I also tried what you mentioned about redirecting stderr to stdout but still it seems to sit there until the program closes.
StdErr should get used though...:

Code: Select all

 62 #define debug(msg) fprintf(stderr, "[AIF]: "#msg"\n")
 63 #define debugarg(msg, arg) fprintf(stderr, "[AIF]: "#msg"\n", arg)
 64 #else
Unless you're capturing the VI/s, in which case StdOut is used (maybe this is what you wanted?)

Code: Select all

140       printf("%.2f VI/s, RCP: %.2f MHZ, VR4300: %.2f MHz\n", vis, hz / 10000,
141         hz / 10000 * 1.5);
If it's the latter, then StdOut could just be getting buffered. What happens if you throw fflush(stdout) after the printf? (in video/Controller.c)? If it works, just use C99 to enable line-buffering for stdout.

User avatar
gamax92
Posts: 22
Joined: Mon Oct 28, 2013 2:07 pm

Re: Unable to read program stdout when running.

Post by gamax92 » Wed Oct 30, 2013 9:13 pm

Ahh yeah, I didn't do a debugging compile and was attempting to capture the "... VI/s " messages that the video writes. I'll try that.

EDIT: Yup, that was it. It needed a fflush. Now its capturing the output, thanks!
What exactly do you mean by enable C99?

User avatar
MarathonMan
Site Admin
Posts: 692
Joined: Fri Oct 04, 2013 4:49 pm

Re: Unable to read program stdout when running.

Post by MarathonMan » Wed Oct 30, 2013 9:24 pm

gamax92 wrote:Ahh yeah, I didn't do a debugging compile and was attempting to capture the "... VI/s " messages that the video writes. I'll try that.

EDIT: Yup, that was it. It needed a fflush. Now its capturing the output, thanks!
What exactly do you mean by enable C99?
I thought setbuf was C99, but it turns out it's C89 as well.

http://man7.org/linux/man-pages/man3/setbuf.3.html

Basically, I was going to suggest that you try other buffering modes to see if it impacted something, but alas it does not!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest