0

I'm trying to use NodeJS with a C program to http://en.wikipedia.org/wiki/Setvbuf for JS files using Fork().

My program.c :

int readTabStr(int k)
{
char * tabString[] = {"p1.js","p2.js","p3.js","p4.js"};
int taille = sizeof(tabString)/sizeof(char);
int i;
    for(i=0; i<taille; i++)
    {
        if (fork() == 0)
        {
            execlp("node","node", tabString[i], NULL);
        }
        else
        {
            wait(NULL);
        }
    }
return 0;
}

I'm using this JS file to launch the C file:

var FFI = require("../../lib/ffi");

var test = new FFI.Library("./readTab", {
"readTabStr": ["int", ["int" ]]  
});

var resultat = test.readTabStr(0);

The problem is that after executing the p1.js, p2.js, p3.jsn p4.js. I get 4 error messages :

node.js:116
throw e; // process.nextTick error, or 'error' event on first tick
^

Error: Cannot find module '/home/fighter/Documents/ffi/kerrighed/execlp/��$[]�U
`enter code here`��E��E��U��S������1�'
at Function._resolveFilename (module.js:299:11)
at Function._load (module.js:245:25)
at Array.<anonymous> (module.js:402:10)
at EventEmitter._tickCallback (node.js:108:26)

Any ideas?

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Wassim AZIRAR
  • 10,823
  • 38
  • 121
  • 174
  • You can accept your own answer as the (only) correct one by clicking on the check mark to the left of the answer. – Bo Persson May 23 '11 at 22:17

1 Answers1

1

Solved,

The problem was

 int taille = sizeof(tabString)/sizeof(char);

I should do :

int taille = sizeof(tabString)/sizeof(char*);

Thanks anyway.

Wassim AZIRAR
  • 10,823
  • 38
  • 121
  • 174
  • Related to your just removed question: see http://jsfiddle.net/Lepfsm9r/1/. Not sure if it is any good, but probably will give you some jump-start. – Wiktor Stribiżew Jun 25 '18 at 16:03
  • I also met some haters today, [here](https://stackoverflow.com/questions/7790761/how-to-replace-only-the-last-match-of-a-string-with-preg-replace/51020307#51020307) and [here](https://stackoverflow.com/questions/51025302/python-regex-match-char-between-two-chars-with-anything-before-or-after-the-m/51025516#51025516). Don't give up :) – Wiktor Stribiżew Jun 25 '18 at 16:14