Monday 30 January 2017

A problem with child_process.spawn and git bash on Windows

tldr; Can't get child_process.spawn to work correctly with git bash on windows..Hi all,I am trying to use child_process.spawn to ssh to a server and do some stuff. On Ubuntu i can use the following code:let spawn = require('child_process').spawn; let child = spawn('ssh', ['-tt', 'username@host']); It will open a GUI for the passphrase for the private key and it is all working. I can add eventlisteners on stdout, stderr and write to stdin.On windows with git bash (without node ) i can ssh and it asks for the passphrase in bash (no extra GUI like Ubuntu). When doing it with Node using this code:let spawn = require('child_process').spawn; let child = spawn('path/to/git/sh.exe'); child.stdout.on('data', (data) => { console.log(data.toString()); } // Same for stderr child.stdin.setEncoding('utf8'); child.stdin.write('ssh -v -tt username@host \n'); It will stop with giving data to stdout before asking Enter passphrase for key:. It blocks the stdin and there is no error.Now to the question: Is there something wrong with my code, git bash (probably security things?) or is this bad use of child_process.spawn ?Thanks for reading! Dirkj143

Submitted January 30, 2017 at 07:43PM by Dirkj143

No comments:

Post a Comment