child_process stdout problems

Talk about add-ons and extension development.
alervd
Posts: 36
Joined: June 6th, 2015, 2:46 am

Re: String as a binary array

Post by alervd »

alervd wrote:receive a data:
process.stdout.on ('data', myfunction);


process.stdout.on ('data', function (MY44BYTEDATAHERE) {
// do stuff...
});

The problem is that MY44BYTEDATAHERE is a string with length = 1.
It contains the very first byte sent by my exe. The remaining 43 bytes sent by my EXE just lost somewhere.
alervd
Posts: 36
Joined: June 6th, 2015, 2:46 am

Re: String as a binary array

Post by alervd »

alervd wrote:This code works fine:

function LenToString (len)
{
return String.fromCharCode (
(len & 0xFF),
(len >> 8) & 0xFF,
(len >> 16) & 0xFF,
(len >> 24) & 0xFF
);
}

String contains all 4 bytes.

Why data does not then?


This is LenToString. It's just my function. It demonstrates that js string CAN contain '\0' characters in it.

sdkEmit is the emit API yes. BUT. I use it to send data to my EXE, not from it!! And it works just fine.
alervd
Posts: 36
Joined: June 6th, 2015, 2:46 am

Re: String as a binary array

Post by alervd »

alervd wrote:
trolly wrote:Which part of the API are you using? Pipes?


send a data:
var sdkEmit = require('sdk/event/core').emit;


Do you read what I post here? This is sdkEmit definition. API from sdk/event/core.
User avatar
trolly
Moderator
Posts: 39851
Joined: August 22nd, 2005, 7:25 am

Re: String as a binary array

Post by trolly »

After rereading APIs, your code etc. I have come to the conclusion that one emit call is exactly related to one call of the listener. You have two emit calls you you should have two listener calls. The first one with the length and the second with the data.
There is no information if events are combined or not.

If this is not the reality I'm out here. I'm out of ideas.

PS: Sometimes I get confused while reading things. Sorry for that.
Think for yourself. Otherwise you have to believe what other people tell you.
A society based on individualism is an oxymoron. || Freedom is at first the freedom to starve.
Constitution says: One man, one vote. Supreme court says: One dollar, one vote.
Noitidart
Posts: 1168
Joined: September 16th, 2007, 8:01 am

Re: String as a binary array

Post by Noitidart »

You know another way to create a null terminated string is to use ctypes:

Code: Select all

Cu.import('resource://gre/modules/ctypes.jsm');

var nullTermedStr = ctypes.char.array()('this is a stirng that will get null termed');
alervd
Posts: 36
Joined: June 6th, 2015, 2:46 am

Re: String as a binary array

Post by alervd »

Post Reply