tags:

views:

125

answers:

1

I'm writing a simple code editor for the LC3 assembly language, and I've run into a small problem. LC3 assembler outputs basic information about the status of assembling which I'm trying to display in my program after reading it back from the log file.

Originally I attempted to use system() to call the LC3 assembler and redirect the stdout and stderr to a file, like so:

system("/pathto/lc3as 1> lc3.log 2>&1");

It outputs to the file but doesn't preserve the order of the output from the assembler.

I have come up with an ugly work around that preserves the order of the output but involves a lot more file IO than I'd like, and I'm not sure if it would work in every situation. On that note, I'm wondering if there is a better solution for routing the output to my program that preserves the order.

+2  A: 

Once you redirect output, the output stream switches from "flush after every write" to "flush only when buffer full" mode. Your stderr output is now going be completely out of sync with the stdout output. You'd have to explicitly call fflush() yourself. Maybe your CRT has a function to change the mode.

Also consider not fixing this. Nobody ever redirects progress chatter to a file, only stderr output matters.

Hans Passant
Hmm, yeah I guess I'm okay with leaving it. Unfortunately the "chatter" in the stdout kinda gives some information about the errors aka what pass the error happens on, but I guess the actual errors might be sufficient.
Evan Huddleston