Skip to content

Any way to use with child_process? #1

@roborourke

Description

@roborourke

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions