On Aug 18, 2013, at 5:52 PM, Mark Hahn <[email protected]> wrote:
> When I run this bash script ...
>
> #!/bin/bash
> tail -f log &
> echo "tail is working" >> log
>
> it prints out "tail is working" as expected.
>
> My question is how can I do the same thing with a node command-line script?
> I've tried everything but I can't come up with anything that works. Most of
> my tries hang with the child_process never returning.
>
> By node command-line script I mean a file like this ...
>
> #!/usr/bin/env node
> console.log "I'm a command-line script”
>
Are you expecting to see “tail is working” (or the equivalent) on the terminal?
I am not entirely comfortable with Node’s child_process (in comparison to Unix
fork/popen) but the documentation does say it is the equivalent of popen, so
‘stdout’ is not going to go to the terminal/tty (assuming you are using *nix).
So, if you have:
var spawn = require(‘child_process’).spawn,
tail = spawn(‘tail’, [‘-f’, ‘log’]);
Then, ostensibly(*) ‘tail.stdout’ will give you the stuff that is being added.
I assume you are watching the file like this, using ’tail -f’, for some reason,
rather than using some tail module.
—ravi
(*) I am speaking generally here since I do not know exactly how you are
spawning the child and how the file content is being modified.
>
> --
> --
> 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 [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
--
--
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.