SpecuCheck icon indicating copy to clipboard operation
SpecuCheck copied to clipboard

add support for redirecting to file

Open greatquux opened this issue 6 years ago • 4 comments

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

greatquux avatar Jan 10 '18 16:01 greatquux

  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.

ionescu007 avatar Jan 10 '18 21:01 ionescu007

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 avatar Jan 11 '18 03:01 greatquux

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.

greatquux avatar Oct 01 '18 19:10 greatquux

Thanks man,

I haven't forgotten about your PR and I do hope to integrate it at some point, hopefully in a cleaner way of such a thing is even possible...

Best regards, Alex Ionescu

On Mon, Oct 1, 2018 at 12:41 PM greatquux [email protected] wrote:

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.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ionescu007/SpecuCheck/pull/15#issuecomment-426036749, or mute the thread https://github.com/notifications/unsubscribe-auth/AFxIeB6ArRd6f8MGAc-RV0d_TIJH48mNks5ugm_qgaJpZM4RZoy6 .

ionescu007 avatar Oct 01 '18 20:10 ionescu007