[ANN] [nodejs] - nexpect - spawn and control child processes with ease. inspired by expect / pexpect.

194 views
Skip to first unread message

Marak Squires

unread,
Sep 18, 2010, 11:30:15 AM9/18/10
to nodejs, nodej...@googlegroups.com, ny...@googlegroups.com
hello internet friends -

a couple of weeks ago Elijah Insua (tmpvar) and myself were trying to work out some graceful child processes scripts and Elijah coded up this neat little project. nexpect builds on node's core spawn methods and allows developers to easily pipe data to child processes and assert the expected response. nexpect also chains, so you can compose complex terminal interactions.

here is some sample code:


var nexpect = require('./lib/nexpect').nspawn;

  nexpect.spawn("echo hello")
         .expect("hello")
         .run(function(err) {
            if (!err) {
              console.log("hello was echoed");
            }
         });

  nexpect.spawn("ls -al /tmp/undefined")
         .expect("No such file or directory")
         .run(function(err) {
            if (!err) {
              console.log("checked that file doesn't exists");
            }
         });

  nexpect.spawn("node")
        .expect("Type '.help' for options.")
        .sendline("console.log('testing')")
        .expect("testing")
        .sendline("process.exit()")
        .run(function(err) {
          if (!err) {
            console.log("node process started, console logged, process exited");
          } else {
            console.log(err)
          }
        });





its barely v0.1.0 right now, so I would expect it has some issues. 

Guillermo Rauch

unread,
Sep 18, 2010, 8:40:38 PM9/18/10
to nod...@googlegroups.com
Beautiful, good work guys!

--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.



--
Guillermo Rauch
http://devthought.com

Michael Russo

unread,
Sep 19, 2010, 12:46:19 PM9/19/10
to nod...@googlegroups.com
This doesn't seem to check the exit code of the process.  Is this deliberate, or simply a TODO?

Thanks,
Michael

Marak Squires

unread,
Sep 19, 2010, 6:12:43 PM9/19/10
to nod...@googlegroups.com
I would think it's a TODO? Let me know if you have a test / demo.

- Marak
Reply all
Reply to author
Forward
0 new messages