[SOLVED] Capture StdOut in UTF-8 format
Posted: 09 Mar 2015, 14:54
I'm using SKAN's code to capture StdOut to a variable:
http://www.autohotkey.com/board/topic/9 ... douttovar/
That thread has questions that haven't been answered in over a year, so it looks like a dead thread. I'm hoping someone on this forum can help.
My issue is that when I use it, the output contains gibberish for the UTF-8 characters. It's the same output you would get running it in a console window. I know the output contains correct UTF-8 characters when I direct it to a file instead, but I don't want to have to access the hard drive for performance reasons (it will be running hundreds of commands in a row). I'd like to capture it directly to a variable.
I tried making the command line chcp 65001 & followed by the usual command line so that it would change the console code page to UTF-8 before executing. It returns nothing when I do that, so it seems this function can't handle compound command lines, even though they work on the console (although in the console, it says not enough memory when I execute it in UTF-8 mode, and even that out of memory message doesn't show as an output of this function, so I think it can't handle putting commands together with &).
I tried changing the dll call for CreateProcess to its Unicode equivalent CreateProcessW, but that also returned a blank.
Does anyone know how to have StdOut produce UTF-8 output so it can be captured in a variable with the correct characters?
Btw, I also tried to convert the actual output to UTF-8 character by character, but the two examples of 2-byte UTF-8 characters I looked at were output as two nonsensical UTF-8 characters. Same format as UTF-8 in that the first byte's high order bits indicate how many bytes it is, and the the second one (and third one when applicable) has the high order bits set as they should be.
http://www.autohotkey.com/board/topic/9 ... douttovar/
That thread has questions that haven't been answered in over a year, so it looks like a dead thread. I'm hoping someone on this forum can help.
My issue is that when I use it, the output contains gibberish for the UTF-8 characters. It's the same output you would get running it in a console window. I know the output contains correct UTF-8 characters when I direct it to a file instead, but I don't want to have to access the hard drive for performance reasons (it will be running hundreds of commands in a row). I'd like to capture it directly to a variable.
I tried making the command line chcp 65001 & followed by the usual command line so that it would change the console code page to UTF-8 before executing. It returns nothing when I do that, so it seems this function can't handle compound command lines, even though they work on the console (although in the console, it says not enough memory when I execute it in UTF-8 mode, and even that out of memory message doesn't show as an output of this function, so I think it can't handle putting commands together with &).
I tried changing the dll call for CreateProcess to its Unicode equivalent CreateProcessW, but that also returned a blank.
Does anyone know how to have StdOut produce UTF-8 output so it can be captured in a variable with the correct characters?
Btw, I also tried to convert the actual output to UTF-8 character by character, but the two examples of 2-byte UTF-8 characters I looked at were output as two nonsensical UTF-8 characters. Same format as UTF-8 in that the first byte's high order bits indicate how many bytes it is, and the the second one (and third one when applicable) has the high order bits set as they should be.