Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for redirecting to file #15

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

greatquux
Copy link

I threw together some quick support for redirecting to a file without altering the pretty console output. ;)

@ionescu007
Copy link
Owner

  1. You shouldn't need to separate WriteFile from WriteConsole. You can WriteFile on a standard output handle.
  2. I don't think you need to detect redirection at all. Calling GetStdHandle(STD_OUTPUT_HANDLE) should natively redirect -- and then the CreateFile(CONOUT can be removed.
  3. No need to call lstrlen(...) * sizeof(WCHAR)...., the existing ARRAYSIZE code works correctly.

@greatquux
Copy link
Author

I have basically 0 experience with straight-up Win32 C programming so there was a bunch of googling and reading stackexchange (this is how everyone passes job interviews these days right? lol) and I didn't really see a lot of idioms where people did everything in WriteFile, they seemed to really detect the redirection and then use one or the other function, but maybe I just wasn't reading the right threads. Also I wanted to not interfere with what you were doing with the console handle since it seemed like you were querying it for ANSI support and stuff and didn't think that would work if I just used stdout. As for ARRAYSIZE when I use that it gives me some junk characters at the end when printing.

@greatquux
Copy link
Author

I took a look at this again since you have released 1.1.0 (thanks again - this will definitely help with those customers who need it and can't use the powershell functions).

When I use WriteFile on STD_OUTPUT_HANDLE I get spaces in the characters at the console:

S p e c u C h e c k v 1 . 1 . 0 - - C o p y r i g h t ( c ) 2 0 1 8 A l e x I o n e s c u

This is why I separated the file and console functions.

There's definitely something that doesn't work right with ARRAYSIZE and WriteFile, it's hard to describe what's going on but if you try it you'll someone's not getting the right number of bytes to print somewhere.

@ionescu007
Copy link
Owner

ionescu007 commented Oct 1, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants