This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: printf goes to serial port?


Bob van Loosen wrote:
> Because of this, the app doesn't get the standard file descriptors for
> stdin, stdout and stderr, also when you open a file the file descriptors
> start at 0.
>
> So what happens is, my app opens a config file, which then becomes
> stdin, then it opens a serial port, which becomes stdout, causing all
> printf statements to go out the serial port.
> The solution is quite simple, just disable all printf statements for a
> cygwin build.

  Well... that requires editing every single printf in the whole program, no?

  It might be easier to just at the start of main() open the first three file
descriptors, so that 0, 1 and 2 are allocated.  If you open 0 from /dev/null
in read mode and open 1 and 2 for write to /dev/null, all your stdio should
behave sensibly.  Then if you decide you want the printfs after all, you can
just change the open to point to a real file and bingo!  Instant log file!

> I have no idea how to get console output when using the
> -mwindows flag, but I don't really need it.

  You probably need to call AllocConsole and open stdio channels to
CONIN$/CONOUT$, but that's off the top of my head and without looking it up.

    cheers,
      DaveK

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]