node.js用于原子中git clone的child_process密码输入

时间:2016-06-15 13:07:53

标签: node.js git atom-editor spawn

我正在尝试克隆一个需要我的atom包中node.js的child_process模块​​的git存储库:

    var spawn = require('child_process').spawn;
    var gitClone = spawn('git', ['clone', 'ssh://user@gitrepo.com/path/to/reponame'], {cwd: path});

    gitClone.stdout.on('data', (data) => {
        gitClone.stdin.write('password');
        console.log(`stdout: ${data}`);
    });

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

    });

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

由于无法使用ssh密钥,我需要将用户密码传递给生成的进程。

我认为this topic也可以解决我的问题,但似乎没有可能进入我的gitClone.stdout.on('data', function (data) { ... }。 我试图在那里执行的任何console.log()都不会显示在Chrome引擎的控制台上。

这是我的输出:

    stderr: Cloning into 'reponame'...
    stderr: Permission denied, please try again.
    stderr: Permission denied, please try again.
    stderr: Permission denied (publickey,password).
    stderr: fatal: Could not read from remote repository.
    Please make sure you have the correct access rights and the repository exists.
    child process exited with code 128

我想知道为什么我只能看到sdterr消息。当我在我的bash中运行git clone时,它首先告诉我Cloning into 'reponame'...,然后它会要求我输入密码。

有没有办法在child_process'中捕获密码提示? spawn()

0 个答案:

没有答案