我试图spawn实现一个rm -rf node_modules跟随npm install(在Windows 7; n x命令由透明安装的CygWin提供.所有n x命令在命令行上解析就好了).
我最初使用它exec,但想要捕获stdout/stderr信息,因此我想我会使用spawn,并重写代码使用它.然而,这打破了一切.
rm重写的命令变为:
var spawn = require("child_process").spawn,
child = spawn("rm", ["-rf", "node_modules"]);
child.stdout.on('data', function (data) { console.log(data.toString()); });
child.stderr.on('data', function (data) { console.log(data.toString()); });
child.on('error', function() { console.log(arguments); });
Run Code Online (Sandbox Code Playgroud)
但是,运行它会生成以下错误:
rm: unknown option -- ,
Try `rm --help' for more information.
Run Code Online (Sandbox Code Playgroud)
npm重写的命令变为:
var spawn = require("child_process").spawn,
child = spawn("npm", ["install"]);
child.stdout.on('data', function (data) { console.log(data.toString()); });
child.stderr.on('data', function (data) { …Run Code Online (Sandbox Code Playgroud) 如何在运行"npm install"时告诉npm使用另一个package.json?
我需要的只是npm install -f packages-win32.json或者有一个技巧或其他方法来实现相同的目标吗?
因为并非所有npm模块都是跨平台的,我想在每个平台上使用其他软件包.