FAQ
Hi all,

I'd like to have my command-line Node program invoke another interactive
shell program (in this case w3m, but think vim, less, and so on) as a child
process so that it appears in my terminal. I thought I could do that like
this:

require('child_process').execFile('w3m', ['http://www.google.com'], {stdio:
'inherit'})

But it turns out that doesn't work. Is this possible?

--
James Coglan
http://jcoglan.com
+44 (0) 7771512510

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Search Discussions

  • James Coglan at Sep 21, 2012 at 11:03 am

    On 21 September 2012 12:40, James Coglan wrote:

    I'd like to have my command-line Node program invoke another interactive
    shell program (in this case w3m, but think vim, less, and so on) as a child
    process so that it appears in my terminal. I thought I could do that like
    this:

    require('child_process').execFile('w3m', ['http://www.google.com'],
    {stdio: 'inherit'})

    But it turns out that doesn't work. Is this possible?
    This is a bit better in that it displays the output from w3m, but it's not
    color formatted (I guess because its stdin is not a tty) and I can't
    interact with it properly:

    var cp = require('child_process'),
    w3m = cp.execFile('w3m', ['http://www.google.com']);

    process.stdin.pipe(w3m.stdin);
    w3m.stdout.pipe(process.stdout);

    So I need to make w3m know it's writing to a tty, and forward every
    keystroke from Node to the child process. I tried
    process.stdin.setRawMode(true) but this just locked the process up and
    CTRL-C and CTRL-Z did not work.

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Ben Noordhuis at Sep 21, 2012 at 1:11 pm

    On Fri, Sep 21, 2012 at 12:40 PM, James Coglan wrote:
    Hi all,

    I'd like to have my command-line Node program invoke another interactive
    shell program (in this case w3m, but think vim, less, and so on) as a child
    process so that it appears in my terminal. I thought I could do that like
    this:

    require('child_process').execFile('w3m', ['http://www.google.com'], {stdio:
    'inherit'})

    But it turns out that doesn't work. Is this possible?
    Yes, but not with the child_process module (not reliably anyway). Try
    https://github.com/chjj/pty.js

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Mark Hahn at Sep 21, 2012 at 6:08 pm
    It amazes me how often a question about some capability of node is answered
    with one or more spot-on solutions. I guess lampp can offer the same
    convenience but node is only a few years old.
    On Fri, Sep 21, 2012 at 6:11 AM, Ben Noordhuis wrote:
    On Fri, Sep 21, 2012 at 12:40 PM, James Coglan wrote:
    Hi all,

    I'd like to have my command-line Node program invoke another interactive
    shell program (in this case w3m, but think vim, less, and so on) as a child
    process so that it appears in my terminal. I thought I could do that like
    this:

    require('child_process').execFile('w3m', ['http://www.google.com'], {stdio:
    'inherit'})

    But it turns out that doesn't work. Is this possible?
    Yes, but not with the child_process module (not reliably anyway). Try
    https://github.com/chjj/pty.js

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • James Coglan at Sep 21, 2012 at 9:22 pm

    On 21 September 2012 12:40, James Coglan wrote:

    I'd like to have my command-line Node program invoke another interactive
    shell program (in this case w3m, but think vim, less, and so on) as a child
    process so that it appears in my terminal. I thought I could do that like
    this:

    require('child_process').execFile('w3m', ['http://www.google.com'],
    {stdio: 'inherit'})
    Turns out I can do what I want using spawn() instead of execFile(). I don't
    quite understand why from the docs -- someone care to enlighten me as to
    what's going on with processes and I/O streams and what the difference is
    between the two functions?

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Tim Caswell at Sep 21, 2012 at 10:17 pm
    execFile is for buffering the output and storing it in a single value
    in the callback. spawn is for streaming the results. My guess is
    execFile ignores the custom stdio pipes.
    On Fri, Sep 21, 2012 at 4:22 PM, James Coglan wrote:
    On 21 September 2012 12:40, James Coglan wrote:

    I'd like to have my command-line Node program invoke another interactive
    shell program (in this case w3m, but think vim, less, and so on) as a child
    process so that it appears in my terminal. I thought I could do that like
    this:

    require('child_process').execFile('w3m', ['http://www.google.com'],
    {stdio: 'inherit'})

    Turns out I can do what I want using spawn() instead of execFile(). I don't
    quite understand why from the docs -- someone care to enlighten me as to
    what's going on with processes and I/O streams and what the difference is
    between the two functions?

    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines:
    https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    Job Board: http://jobs.nodejs.org/
    Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    You received this message because you are subscribed to the Google
    Groups "nodejs" group.
    To post to this group, send email to nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupnodejs @
categoriesnodejs
postedSep 21, '12 at 10:48a
activeSep 21, '12 at 10:17p
posts6
users4
websitenodejs.org
irc#node.js

People

Translate

site design / logo © 2022 Grokbase