2

I have a program I run programmatically on Node.js using child_process.

var spawnedProcess = childProcess.spawn(command, args);

spawnedProcess.stdout.setEncoding("utf8");
spawnedProcess.stdout.on("data", function(data) {
  return process.stdout.write(data);
});

process.stdin.pipe(spawnedProcess.stdin);

I thought this would work since everything I type into the shell would be piped into the stdin of the spawned process.

I can see what I am typing and when I hit Enter it just give me a new line. The shell isn't responding to any input.

Any clue?

3
  • What is the command you're trying to run? Commented Nov 20, 2011 at 10:17
  • "npm init" and "jitsu deploy". Commented Nov 20, 2011 at 12:40
  • npm can be used programmatically (you can install it as a module), not sure about jitsu. Commented Nov 20, 2011 at 12:45

1 Answer 1

1

As mentioned in the comments, you can potentially actually use both npm and jitsu both can potentially be used directly as modules. You may want to consider that as an option.

When you run them from the command line, all you are doing is running these two scripts:

To answer your question though, it looks totally fine except for one bit. You need to resume the stdin stream before it can be piped, as mentioned in it's docs Docs for process.stdin

You just need to add this somewhere around where you call 'pipe'.

process.stdin.resume()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.