execve in node

201 views
Skip to first unread message

Daniel Risacher

unread,
Jan 10, 2017, 8:35:53 AM1/10/17
to nodejs
Is it possible to execute another program in the manner of execve(2)?  

I.e. as the man page says, "execve() does not return on success, and the text, data, bss, and stack of the calling process are overwritten by that of the program loaded."

I don't see any function in the core modules that does this.  

Matt

unread,
Jan 12, 2017, 9:53:38 AM1/12/17
to nod...@googlegroups.com
No there's no equivalent to it, mostly because Windows has no way to do it. Maybe try perl instead.

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 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 unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/026d265f-93a4-4369-ae5e-7ef6433e0d3e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Daniel Risacher

unread,
Jan 16, 2017, 9:11:16 AM1/16/17
to nodejs
I find deep irony in your answer, in that I was trying to rewrite a simple script that I'd already written in perl with a nodejs version to eliminate the perl dependency.


On Thursday, January 12, 2017 at 9:53:38 AM UTC-5, Matt Sergeant wrote:
No there's no equivalent to it, mostly because Windows has no way to do it. Maybe try perl instead.
On Fri, Jan 6, 2017 at 5:08 PM, Daniel Risacher <dris...@gmail.com> wrote:
Is it possible to execute another program in the manner of execve(2)?  

I.e. as the man page says, "execve() does not return on success, and the text, data, bss, and stack of the calling process are overwritten by that of the program loaded."

I don't see any function in the core modules that does this.  

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 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 unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.

Fedor Indutny

unread,
Jan 16, 2017, 2:34:25 PM1/16/17
to nod...@googlegroups.com
I'm not sure if it helps, but have you already tried child_process.spawnSync?

Matt

unread,
Jan 17, 2017, 12:22:30 PM1/17/17
to nod...@googlegroups.com
cp.spawn/spawnSync have very different semantics to execve though. They maintain a parent process, which I imagine is what Daniel is trying to avoid.

To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.



To post to this group, send email to nod...@googlegroups.com.


To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/0e858cf2-d3de-44d9-aa2e-18805cd764d4%40googlegroups.com.


For more options, visit https://groups.google.com/d/optout.


--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 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 unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.

To post to this group, send email to nod...@googlegroups.com.

Daniel Risacher

unread,
Jan 17, 2017, 12:22:30 PM1/17/17
to nod...@googlegroups.com
Well, clearly it is possible to achieve the broad objective of
starting a new program with child_process.spawnSync(). In my case, I
do not need the nodejs process afterwards, I do not need to capture
the output of the program, and the only thing that node would be doing
is waiting to call exit() with the right value.

"Just use perl" is simpler, although I think I may try
require('ffi').Library(null, { 'execve': .... })

On Mon, Jan 16, 2017 at 2:26 PM, Fedor Indutny <fe...@indutny.com> wrote:
> You received this message because you are subscribed to a topic in the
> Google Groups "nodejs" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/nodejs/4vtWG1KCQC4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> nodejs+un...@googlegroups.com.
> To post to this group, send email to nod...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nodejs/CAEv2VfKFHS803Lh9srVB%3DqSy-wFi20j6%2B%2BDEfo%2BQcg74aStb3A%40mail.gmail.com.

selenag...@yahoo.com

unread,
Jan 18, 2017, 1:10:01 PM1/18/17
to nod...@googlegroups.com

--------------------------------------------
On Tue, 1/17/17, Daniel Risacher <d...@risacher.org> wrote:

Subject: Re: [nodejs] execve in node
To: nod...@googlegroups.com
Date: Tuesday, January 17, 2017, 4:04 PM
https://groups.google.com/d/msgid/nodejs/CAAD1OeKFTtYqebXDy6jbUbVmsoZr_a3KJo6CVvzyMYWZ8TLQ1Q%40mail.gmail.com.
For
more options, visit https://groups.google.com/d/optout.
evolutia de la 1848 cauta a reintregi pe roman numai in drepturile sale de om si de cetatean fara a cauta a-! reintregi in drepturile sale de natie. intr-aceasta ea se margini a cere ca Turcia sa respecte vechile capitulatii recunoscute si intarite si prin tratatul de la Adnanopol si Hatiseriful de la 1834. Ea ceru asemenea ca Rusia sa-si pazeasca tractatele care recunosc autonomia si independenta administrativa a terii si nesihrea pamantului ei si sa se margineasca in rolul ei de chezasa fara a se amesteca in treburile din launtru ale teni usurpand titlul si rolul de protectoare Revolutia de la 1848 nu era dar in drept impotrivitoare nici Portii nici Rusiei devreme ce se marginea a cere pazirea tractatelor fara a proclama un drept nou. Romanii in buna credinta a lor socoteau ca aceste Puteri vor fi gata a pazi sfintenia tractatelor si nu vor putea a le tagadui reformarea legiuirilor potrivit dreptului lor de autonomie .

vincent...@yahoo.com

unread,
Jan 19, 2017, 5:17:01 PM1/19/17
to nod...@googlegroups.com

--------------------------------------------
On Wed, 1/18/17, selenagracia795 via nodejs <nod...@googlegroups.com> wrote:

Subject: Re: [nodejs] execve in node
To: nod...@googlegroups.com
Date: Wednesday, January 18, 2017, 4:52 PM
https://groups.google.com/d/msgid/nodejs/1061562350.5363901.1484751176400%40mail.yahoo.com.
For more options, visit
https://groups.google.com/d/optout.pogeul contradictiilor intre Bucuresti si Moscova a fost inregistrat in aprilie 1964 cand s-a publicat Planul Va ev. Acesta prevedea realizarea unui complex economic care sa cuprinda sudul Uniunii Sovietice sud-vestul Romaniei si nordul Bulgariei si care urma sa reprezinte un veritabil granar specializat aproape exclusiv pe productia agricola in deterimentul celei industriale. Comunistii romani au reactionat violent si au ripostat afirmand ca era vorba de o incercare de dezmembrare economica a Romaniei. in aceste conditii agravate de situarea tot mai deschisa a autoritatilor romane de partea Beijingului in conflictul cu Moscova a intervenit in aprilie 1964 Delegatia cu privire la pozitia Partidului Muncitoresc Roman in problemele miscarii comuniste si muncitoresti internationale. Documentul propunea statuarea de noi principii in relatiile intre partidele comuniste - egalitate avantaj reciproc neamestec in afacerile interne s.a. in acelasi timp documentul incerca pentru prima data a fi baza teoretica a unei reconcilieri intre partidul comunist si poporul roman al carei punct culminant a foat atins in august 1968 in cadrul marelui miting de la Bucuresti cand a fost criticata agresiunea Pactului de la Varsovia in Cehoslovacia actiune la care Romania a refuzat sa participe.

Daniel Risacher

unread,
Jan 19, 2017, 5:17:23 PM1/19/17
to nod...@googlegroups.com
For future reference, here is a way to use execvp() from node:

const ffi = require('ffi');
const ref = require('ref');
const ArrayType = require('ref-array');
const stringAry = ArrayType('string');
var current = ffi.Library(null,
{ execvp: ['int', ['string',
stringAry]],
dup2: ['int', ['int', 'int']]});
current.dup2(process.stdin._handle.fd, 0);
current.dup2(process.stdout._handle.fd, 1);
current.dup2(process.stderr._handle.fd, 2);
var ret = current.execvp("/usr/bin/program", ['progname', 'arg1, 'arg2',
arg3, ref.NULL]);
>>> https://groups.google.com/d/msgid/nodejs/0e858cf2-d3de-44d9-aa2e-18805cd764d4%40googlegroups.com.
>>>
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>> --
>> Job board: http://jobs.nodejs.org/
>> New group rules:
>> https://gist.github.com/othiym23/9886289#file-moderation-policy-md
>> Old group rules:
>> 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 unsubscribe from this group and stop receiving emails from it, send an
>> email to nodejs+un...@googlegroups.com.
>> To post to this group, send email to nod...@googlegroups.com.
>> To view this discussion on the web visit
> You received this message because you are subscribed to a topic in the
> Google Groups "nodejs" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/nodejs/4vtWG1KCQC4/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> nodejs+un...@googlegroups.com.
> To post to this group, send email to nod...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nodejs/CAPJ5V2Z54nrCzGSUFAs2TvLPSHNivG-6WUH5UkXjGZWk1PfOLA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages