node-expect icon indicating copy to clipboard operation
node-expect copied to clipboard

Any way to use with child_process?

Open roborourke opened this issue 8 years ago • 2 comments

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' ]))
  })
}

roborourke avatar Nov 02 '16 12:11 roborourke

I haven't looked at this code in a while. Let me see what I can do to make this work.

Trakkasure avatar Nov 05 '16 04:11 Trakkasure

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 !

Grenadingue avatar Nov 29 '16 17:11 Grenadingue