[英]Can't spawn `gcloud app deploy` from a Node.js script on Windows
I'm building an Electron application (Node.js) which needs to spawn gcloud app deploy
from the application with realtime feedback (stdin/stdout/stderr). 我正在构建一个Electron应用程序(Node.js),该应用程序需要从具有实时反馈(stdin / stdout / stderr)的应用程序中生成
gcloud app deploy
。
I rapidly switched from child_process
to execa because I had some issues on Mac OS X with the child_process buffer which is limited to 200kb (and gcloud app deploy
sends some big chunk of string > 200kb which crash the command). 我
child_process
迅速从child_process
切换为child_process
, 是因为在Mac OS X上,child_process缓冲区限制为200kb(在gcloud app deploy
发送一些大的字符串> 200kb,这会使命令崩溃)时出现了一些问题。
Now, with execa
everything seems to work normally on OSX but not on Windows. 现在,有了
execa
一切似乎都可以在OSX上正常运行,但不能在Windows上正常运行。
The code looks something like this: 代码看起来像这样:
let bin = `gcloud${/^win/.test(process.platform) ? '.cmd' : ''}`
//which: https://github.com/npm/node-which
which(bin, (err, fullpath) => {
let proc = execa(fullpath, ['app', 'deploy'], {
cwd: appPath
})
proc.stdout.on('data', data => {
parseDeploy(data.toString())
})
proc.stderr.on('data', data => {
parseDeploy(data.toString())
})
proc.then(() => {
...
}).catch(e => {
...
})
})
This code works perfectly on Mac OS X while I haven't the same result on Windows 这段代码在Mac OS X上可以完美运行,而在Windows上却无法获得相同的结果
I have tried lots of thing: 我尝试了很多事情:
I have made a GIST to show the responses I get for some tests I have done on Windows with basic Child Process scripts: https://gist.github.com/thyb/9b53b65c25cd964bbe962d8a9754e31f 我做了一个GIST,以显示我在Windows上使用基本的子进程脚本进行的一些测试所得到的响应: https : //gist.github.com/thyb/9b53b65c25cd964bbe962d8a9754e31f
I also opened an issue on execa
repository: https://github.com/sindresorhus/execa/issues/97 我还在
execa
存储库上打开了一个问题: https : //github.com/sindresorhus/execa/issues/97
Does someone already got this issue ? 有人已经遇到这个问题了吗? I've searched around and found nothing promising except this reddit thread which doesn't solve this issue.
我四处搜寻,除了没有解决这个问题的Reddit线程外,没有其他希望。
Behind the scene, gcloud.cmd is running a python script. 在后台,gcloud.cmd正在运行python脚本。 After reading tons of Node.js issue with ChildProcess / Python and Windows, I fell on this thread: https://github.com/nodejs/node-v0.x-archive/issues/8298
在阅读了有关ChildProcess / Python和Windows的大量Node.js问题之后,我落入了这个线程: https : //github.com/nodejs/node-v0.x-archive/issues/8298
There is some known issue about running Python scripts from a Node.js Child Process. 关于从Node.js子进程运行Python脚本存在一些已知问题。 They talk in this comment about an unbuffered option for python.
他们在此评论中谈到python的无缓冲选项。 After updating the shell script in
gcloud.cmd
by adding the -u
option, I noticed everything was working as expected 通过添加
-u
选项更新gcloud.cmd
的shell脚本后,我注意到一切都按预期工作
This comment explains how to set this option as an environment variable (to not modify the windows shell script directly): https://docs.python.org/2/using/cmdline.html#envvar-PYTHONUNBUFFERED 此注释说明了如何将此选项设置为环境变量(不直接修改Windows Shell脚本): https : //docs.python.org/2/using/cmdline.html#envvar-PYTHONUNBUFFERED
So adding PYTHONUNBUFFERED
to the environment variable fix this issue ! 因此,将
PYTHONUNBUFFERED
添加到环境变量可以解决此问题!
execa(fullpath, ['app', 'deploy'], {
cwd: appPath,
env: Object.assign({}, process.env, {
PYTHONUNBUFFERED: true
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.