Node.js grouping stdout from chid_process c applicationHow do I debug Node.js applications?How do I get started with Node.jsWriting files in Node.jsHow do I pass command line arguments to a Node.js program?Check synchronously if file/directory exists in Node.jsRead environment variables in Node.jsHow to decide when to use Node.js?How to exit in Node.jsWhat is the purpose of Node.js module.exports and how do you use it?Using node.js as a simple web server

Why did Boris Johnson call for new elections?

Why does the seven segment display have decimal point at the right?

Round away from zero

Is it a missed optimization, when a compile-time known reference takes space in a struct?

Supervisor wants me to support a diploma-thesis SW tool after I graduated

Draw the ☣ (Biohazard Symbol)

Temporarily simulate being offline programmatically

How does the UK House of Commons think they can prolong the deadline of Brexit?

Book where main character comes out of stasis bubble

Male viewpoint in an erotic novel

Global variables and information security

Did the Byzantines ever attempt to move their capital to Rome?

What is the name for quantum gates that can be reversed?

How can I hint that my character isn't real?

Can you create water inside someone's mouth?

Notation: grace note played on the beat with a chord

These roommates throw strange parties

When should IGNORE_DUP_KEY option be used on an index?

How to measure the statistical "distance" between two frequency distributions?

What would happen if you robbed the momentum from a falling object?

How should Thaumaturgy's "three times as loud as normal" be interpreted?

Friend is very nit picky about side comments I don't intend to be taken too seriously

Why did Tony's Arc Reactor do this?

Is future tense in English really a myth?



Node.js grouping stdout from chid_process c application


How do I debug Node.js applications?How do I get started with Node.jsWriting files in Node.jsHow do I pass command line arguments to a Node.js program?Check synchronously if file/directory exists in Node.jsRead environment variables in Node.jsHow to decide when to use Node.js?How to exit in Node.jsWhat is the purpose of Node.js module.exports and how do you use it?Using node.js as a simple web server






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm connecting a remote client to a c application via a node.js service and am having trouble separating the printf() statements from the c application when output from the node.js app.



When the printf() statements happen in quick succession, the node.js application prints them together. This is causing errors for the client parsing that output.



As I'm new to c and still early in node.js, my testing has lead me to guess that the issue is related to how node.js handles the stdout stream from the child_process.



I should also note that the output is not consistently incorrect. There are a few places in the code where it's more variable and correlated to the speed of user inputs (this is for a game). The example I've shared below is the case where the output most consistently incorrect.



I've tried:



  • Running the c program directly. (This gives me the expected [correct] result)

  • Adjusting the buffer size in c with setvbuf (Unexpected result from the node.js application)

  • Running the c application from node with the synchronous and asynchronous versions of both spawn and exec (Unexpected result from the node.js application)

Here's a portion of the c application:



void readPin(int outputPin)

if(output[lightPins[light]] == outputPin)
reportGameStatus("light match");
lightSuccess();

...


void lightSuccess()
reportGameStatus("light success");
...



void reportGameStatus(char* event)
printf(""
""event":"%s","
"n",
event
);

fflush(stdout);



And here's the node.js portion:



var spawn = require("child_process").spawn;
var process = spawn("./cApplication");

process.stdout.on('data',function(msg)
console.log('stdout: ' + msg);
...
);


This results in the following output from the node.js application:



stdout: "event":"light match""event":"light success"


Expected result:



stdout: "event":"light match"
stdout: "event":"light success"









share|improve this question


























  • Your listed output is not what your reportGameStatus() function prints out...

    – Shawn
    Mar 28 at 5:43











  • @Shawn The errant output is variable and does not always show up. There are a few cases in the application where this happens less consistently and dependent on the speed of user inputs. The case I've shared here is most consistently incorrect, however. I'll edit the post with that info.

    – justmydisplayname
    Mar 28 at 15:14


















1















I'm connecting a remote client to a c application via a node.js service and am having trouble separating the printf() statements from the c application when output from the node.js app.



When the printf() statements happen in quick succession, the node.js application prints them together. This is causing errors for the client parsing that output.



As I'm new to c and still early in node.js, my testing has lead me to guess that the issue is related to how node.js handles the stdout stream from the child_process.



I should also note that the output is not consistently incorrect. There are a few places in the code where it's more variable and correlated to the speed of user inputs (this is for a game). The example I've shared below is the case where the output most consistently incorrect.



I've tried:



  • Running the c program directly. (This gives me the expected [correct] result)

  • Adjusting the buffer size in c with setvbuf (Unexpected result from the node.js application)

  • Running the c application from node with the synchronous and asynchronous versions of both spawn and exec (Unexpected result from the node.js application)

Here's a portion of the c application:



void readPin(int outputPin)

if(output[lightPins[light]] == outputPin)
reportGameStatus("light match");
lightSuccess();

...


void lightSuccess()
reportGameStatus("light success");
...



void reportGameStatus(char* event)
printf(""
""event":"%s","
"n",
event
);

fflush(stdout);



And here's the node.js portion:



var spawn = require("child_process").spawn;
var process = spawn("./cApplication");

process.stdout.on('data',function(msg)
console.log('stdout: ' + msg);
...
);


This results in the following output from the node.js application:



stdout: "event":"light match""event":"light success"


Expected result:



stdout: "event":"light match"
stdout: "event":"light success"









share|improve this question


























  • Your listed output is not what your reportGameStatus() function prints out...

    – Shawn
    Mar 28 at 5:43











  • @Shawn The errant output is variable and does not always show up. There are a few cases in the application where this happens less consistently and dependent on the speed of user inputs. The case I've shared here is most consistently incorrect, however. I'll edit the post with that info.

    – justmydisplayname
    Mar 28 at 15:14














1












1








1








I'm connecting a remote client to a c application via a node.js service and am having trouble separating the printf() statements from the c application when output from the node.js app.



When the printf() statements happen in quick succession, the node.js application prints them together. This is causing errors for the client parsing that output.



As I'm new to c and still early in node.js, my testing has lead me to guess that the issue is related to how node.js handles the stdout stream from the child_process.



I should also note that the output is not consistently incorrect. There are a few places in the code where it's more variable and correlated to the speed of user inputs (this is for a game). The example I've shared below is the case where the output most consistently incorrect.



I've tried:



  • Running the c program directly. (This gives me the expected [correct] result)

  • Adjusting the buffer size in c with setvbuf (Unexpected result from the node.js application)

  • Running the c application from node with the synchronous and asynchronous versions of both spawn and exec (Unexpected result from the node.js application)

Here's a portion of the c application:



void readPin(int outputPin)

if(output[lightPins[light]] == outputPin)
reportGameStatus("light match");
lightSuccess();

...


void lightSuccess()
reportGameStatus("light success");
...



void reportGameStatus(char* event)
printf(""
""event":"%s","
"n",
event
);

fflush(stdout);



And here's the node.js portion:



var spawn = require("child_process").spawn;
var process = spawn("./cApplication");

process.stdout.on('data',function(msg)
console.log('stdout: ' + msg);
...
);


This results in the following output from the node.js application:



stdout: "event":"light match""event":"light success"


Expected result:



stdout: "event":"light match"
stdout: "event":"light success"









share|improve this question
















I'm connecting a remote client to a c application via a node.js service and am having trouble separating the printf() statements from the c application when output from the node.js app.



When the printf() statements happen in quick succession, the node.js application prints them together. This is causing errors for the client parsing that output.



As I'm new to c and still early in node.js, my testing has lead me to guess that the issue is related to how node.js handles the stdout stream from the child_process.



I should also note that the output is not consistently incorrect. There are a few places in the code where it's more variable and correlated to the speed of user inputs (this is for a game). The example I've shared below is the case where the output most consistently incorrect.



I've tried:



  • Running the c program directly. (This gives me the expected [correct] result)

  • Adjusting the buffer size in c with setvbuf (Unexpected result from the node.js application)

  • Running the c application from node with the synchronous and asynchronous versions of both spawn and exec (Unexpected result from the node.js application)

Here's a portion of the c application:



void readPin(int outputPin)

if(output[lightPins[light]] == outputPin)
reportGameStatus("light match");
lightSuccess();

...


void lightSuccess()
reportGameStatus("light success");
...



void reportGameStatus(char* event)
printf(""
""event":"%s","
"n",
event
);

fflush(stdout);



And here's the node.js portion:



var spawn = require("child_process").spawn;
var process = spawn("./cApplication");

process.stdout.on('data',function(msg)
console.log('stdout: ' + msg);
...
);


This results in the following output from the node.js application:



stdout: "event":"light match""event":"light success"


Expected result:



stdout: "event":"light match"
stdout: "event":"light success"






c node.js






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 15:17







justmydisplayname

















asked Mar 28 at 5:02









justmydisplaynamejustmydisplayname

217 bronze badges




217 bronze badges















  • Your listed output is not what your reportGameStatus() function prints out...

    – Shawn
    Mar 28 at 5:43











  • @Shawn The errant output is variable and does not always show up. There are a few cases in the application where this happens less consistently and dependent on the speed of user inputs. The case I've shared here is most consistently incorrect, however. I'll edit the post with that info.

    – justmydisplayname
    Mar 28 at 15:14


















  • Your listed output is not what your reportGameStatus() function prints out...

    – Shawn
    Mar 28 at 5:43











  • @Shawn The errant output is variable and does not always show up. There are a few cases in the application where this happens less consistently and dependent on the speed of user inputs. The case I've shared here is most consistently incorrect, however. I'll edit the post with that info.

    – justmydisplayname
    Mar 28 at 15:14

















Your listed output is not what your reportGameStatus() function prints out...

– Shawn
Mar 28 at 5:43





Your listed output is not what your reportGameStatus() function prints out...

– Shawn
Mar 28 at 5:43













@Shawn The errant output is variable and does not always show up. There are a few cases in the application where this happens less consistently and dependent on the speed of user inputs. The case I've shared here is most consistently incorrect, however. I'll edit the post with that info.

– justmydisplayname
Mar 28 at 15:14






@Shawn The errant output is variable and does not always show up. There are a few cases in the application where this happens less consistently and dependent on the speed of user inputs. The case I've shared here is most consistently incorrect, however. I'll edit the post with that info.

– justmydisplayname
Mar 28 at 15:14













0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55390493%2fnode-js-grouping-stdout-from-chid-process-c-application%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.




















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55390493%2fnode-js-grouping-stdout-from-chid-process-c-application%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현