node-expect
node-expect copied to clipboard
Any way to use with child_process?
Hi, is there a way to use this with child_process.spawn
?
I've tried passing stdin
and stdout
to .monitor()
, I've tried using this library: https://github.com/stream-utils/duplex-child-process but I'm not having any luck.
My code looks like this:
import dps from 'duplex-child-process'
export function addKey( password ) {
return new Promise( (resolve, reject) => {
const parser = new Expect()
parser
.conversation(/ssh-add/)
.sync()
.expect(/Enter passphrase/)
.send(`${password}\n`)
.branch(/Identity added/)
.handler(()=> { console.log('added'); resolve() })
.branch(/Bad passphrase/)
.handler(()=> { console.log('bad'); reject() })
.end()
parser.write("ssh-add\n")
parser.monitor(dps.spawn('ssh-add', [ '-K', '~/.ssh/id_rsa' ]))
})
}
I haven't looked at this code in a while. Let me see what I can do to make this work.
Hi, just wanted to bump, I'm very interested by using your project with child_process.spawn()
too
I tried to make it work by myself but I'm a bit lost in the code. Anyway, if I can do anything that can accelerate resolving this issue, I'd be happy to help !