-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
lib: Attempted to fix issue #57780, child_process.js #57956
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"dependencies": { | ||
"iconv-lite": "^0.6.3" | ||
} | ||
} | ||
Comment on lines
+1
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you can imagine, we're not going to want to have this file |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Testing for issue 57780, works on MacOS and Windows,link here: | ||
// https://github.com/nodejs/node/issues/57780 | ||
|
||
const child_process = require('child_process'); | ||
const iconv = require('iconv-lite'); // Still needed for Windows testing | ||
|
||
const isWindows = process.platform === 'win32'; | ||
|
||
async function amain() { | ||
if (isWindows) { | ||
// Windows: Test cmd.exe with UTF-8 + GBK | ||
const cp = child_process.spawn('cmd', [], { | ||
stdio: ['pipe', 'inherit', 'inherit'], | ||
env: { ...process.env, CHCP: '65001' } // Force UTF-8 | ||
}); | ||
|
||
const utf8Cmd = 'echo utf8中文测试\r\n'; | ||
const gbkCmd = iconv.encode('echo gbk中文测试\r\n', 'gbk'); | ||
|
||
cp.stdin.write(utf8Cmd); | ||
cp.stdin.write(gbkCmd); | ||
cp.stdin.end(); | ||
} else { | ||
// macOS: Test UTF-8 in bash | ||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are many more OSes which are neither Windows nor macOS |
||
console.log('Testing UTF-8 on macOS:'); | ||
const bash = child_process.spawn('bash', ['-c', 'echo "macOS中文测试"']); | ||
bash.stdout.pipe(process.stdout); | ||
} | ||
} | ||
|
||
amain().catch(console.error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introducing a class just to "highjack" spawnings of
cmd.exe
on Windows doesn't feel right – it's unclear whether we'd want to fix #57780 in the first place tbh