4

I'm looking for a command like Ruby's kernel 'exec' but for Node.js. Any thoughts?

4
  • Could you describe what you want to do with it? Commented Dec 2, 2011 at 20:27
  • Yes, I want to replace the running process with the child process in and identical manner to Ruby's 'exec'. Commented Dec 2, 2011 at 20:30
  • For those of us familiar with Node but not Ruby, perhaps you could explain why Node's child_process.exec is not satisfactory. Commented Dec 2, 2011 at 20:30
  • @MДΓΓБДLL I want to replace the running process with the child process. Write a quick ruby script to test this behavior, put only the following line: exec('node'). You'll notice that the ruby interpreter is now the node interpreter. Commented Dec 2, 2011 at 20:33

2 Answers 2

7

I took the advice of @phs and built a native Node.js module. A bit of details can be found here. Github source here.

You can use it like so:

npm install kexec

var kexec = require('kexec'); kexec("your_process with args here"); 
Sign up to request clarification or add additional context in comments.

1 Comment

Trying to decide if I can afford the time to patch this for Windows support. (It's clearly possible, both Ruby's exec() and Python's execv() are cross-platform.)
5

If you only care about posix platforms you could craft a small module in C and drop down to exec.

For some pointers on how you might do that, first realize that node is a framework that runs on top of v8, and then take a look at this or perhaps this.

3 Comments

Awesome. Any tutorials on how I can do this?
@JPRichardson You're looking at getting dirty with v8 extensions. I've updated the answer with a few links to get started.
Thanks, I gave you an upvote as I didn't think of this as an option previously.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.