-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 remarks for StandardInputEncoding #6849
base: main
Are you sure you want to change the base?
Conversation
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
Docs Build status updates of commit d9c97fd: ✅ Validation status: passed
For more details, please refer to the build report. Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report. For any questions, please:
|
Tagging subscribers to this area: @carlossanlop Issue DetailsDo reword my content if necessary. ReasonThis is a C Program that reads by UTF16: #include <io.h>
#include <fcntl.h>
#include <stdio.h>
#include <wchar.h>
int main() {
_setmode(_fileno(stdin), _O_U16TEXT);
_setmode(_fileno(stdout), _O_U16TEXT);
wchar_t input[10] = {};
fgetws(input, 10, stdin);
wprintf(L"%X\n", input[0]);
fputws(input, stdout);
} When executing it from Console, it works normally. For example type
But when executing it from C# with using System;
using System.Text;
using System.Diagnostics;
class Program {
static void Main() {
ProcessStartInfo psi = new() {
FileName = "tr.exe",
UseShellExecute = false,
RedirectStandardInput = true,
StandardInputEncoding = Encoding.Unicode,
// StandardInputEncoding = new UnicodeEncoding(false, false),
RedirectStandardOutput = true,
StandardOutputEncoding = Encoding.Unicode
};
var p = Process.Start(psi);
p.StandardInput.WriteLine("asdf");
p.WaitForExit();
string s = p.StandardOutput.ReadToEnd();
Console.WriteLine(s);
}
} The output:
The The correct way is to use
|
Co-authored-by: Krzysztof Wicher <[email protected]>
Docs Build status updates of commit 25b152e: ✅ Validation status: passed
For more details, please refer to the build report. Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report. For any questions, please:
|
Docs Build status updates of commit 71cc355: ✅ Validation status: passed
For more details, please refer to the build report. Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report. For any questions, please:
|
Docs Build status updates of commit 71cc355: ✅ Validation status: passed
For more details, please refer to the build report. Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report. For any questions, please:
|
Do reword my content if necessary.
Reason
This is a C Program that reads by UTF16:
When executing it from Console, it works normally. For example type
asdf
:But when executing it from C# with
Encoding.Unicode
, it won't work normally:The output:
FEFF
is UTF16 BE BOM. I think it's because C is LE, the actual bytes areFF, FE
, UTF16 LE, but when outputing the FE is interpreted as high part.The correct way is to use
new UnicodeEncoding(false, false)
.