The problem of using non-ASCII characters in Windows using BufferedProcess


#1

Hi:
I tried to call git grep via BufferedProcess, however, when I passed Chinese characters to it, an error has occurred.

OS: Windows 7
Atom version: 1.28.2 x64
git version: git version 2.17.0, on cygwin

atom = require("atom")
new atom.BufferedProcess({
    command: "git",
    args: ["grep", "-i", "--no-color", "测试"],
    stdout: console.log,
    stderr: console.log,
    exit: console.log,
    options: {
        cwd: "path/to/a/repo"
    }
});

And I get a error:

fatal: command line, '"测试"': brackets ([ ]) not balanced
128

Thank you.


#2

There are numerous possible reasons, most related to encoding.
Here’s a couple of tests:

  • Does it work directly in the command line?
  • Does it work when running as a Nodejs child_process?

#3

Thanks for your suggestion.

I tested the code:

child_process.exec("git grep -i --no-color 测试", {
    cwd:"/path/to/a/repo" 
}, console.log);

And I get a error:

Error: Command failed: git grep -i --no-color 测试
fatal: command line, '测试': brackets ([ ]) not balanced


    at ChildProcess.exithandler (child_process.js:287)
    at emitTwo (events.js:126)
    at ChildProcess.emit (events.js:214)
    at maybeClose (internal/child_process.js:925)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:209) "" "fatal: command line, '测试': brackets ([ ]) not balanced

It seems that this problem has little relation with the atom.


#4

I found the reason. Maybe it’s because I use git in the cgywin environment. Executing git in cmd will also get the same error.