gpt4 book ai didi

android - 从 nodejs 运行 gradlew

转载 作者:行者123 更新时间:2023-11-29 01:19:02 25 4
gpt4 key购买 nike

尝试从 nodeJS 运行 gradlew:

const spawn = require('child_process').spawn;
const path = require('path');

function run() {

var path_dir = path.resolve('./../movies/VanillaApp/android');

var options = {
cwd: path_dir
};

const ls = spawn('gradlew', ['assembleRelease'], options);

ls.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});

ls.stderr.on('data', (data) => {
console.log(`stderr: ${data}`);
});

ls.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});

}



module.exports = {
run: run
};

终端等价物:

> ./gradlew assembleRelease

获得:

events.js:154
throw er; // Unhandled 'error' event
^

Error: spawn gradlew ENOENT
at exports._errnoException (util.js:856:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)
at onErrorNT (internal/child_process.js:344:16)
at _combinedTickCallback (node.js:377:13)
at process._tickCallback (node.js:401:11)
at Function.Module.runMain (module.js:449:11)
at startup (node.js:141:18)
at node.js:933:3

更新:

我已经成功运行了 child_process.exec 但没有运行 spawn。

最佳答案

我自己偶然发现了这个问题,并设法使用 --project-dir 运行 gradlewspawn命令行选项:

var taskDone = this.async();

grunt.util.spawn({
cmd: "my/relative/path/gradlew",
args: ["clean", "--project-dir", "my/relative/path"],
opts: {
stdio: "inherit"
}
}, function (error, result) {
if (error) {
taskDone(false);
} else {
taskDone();
}
});

关于android - 从 nodejs 运行 gradlew,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37993639/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com