Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8234821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:36:41+00:00 2026-06-07T18:36:41+00:00

Here is my Node.JS code var rec = spawn(‘rec.exe’); rec.stdout.setEncoding(‘ascii’); rec.stdout.on(‘data’, function (data) {

  • 0

Here is my Node.JS code

var rec = spawn('rec.exe');
rec.stdout.setEncoding('ascii');
rec.stdout.on('data', function (data) {
console.log(data);
    //do something
}
);

And my C++ program (compiled by Cygwin) writes something to stdout using printf().

if(bufsize!=0&&rec[0]=='0')
    {
    printf("%s\n",rec);
    //printf("Received,write into exchange file\n");
    //fp=fopen("recvdata.txt","w");
    //fprintf(fp,"%s\n",rec);
        //fclose(fp);
}

But the data event is never emitted.

I’m sure there is something wrong with my C++ code because it works with some other commands like ping.

Then I noticed that in this case, the event is emitted

if(fd==-1)
{
    printf("Failed,again\n");
    return 0;
}

It means when the process exits, everything works fine. But that’s not what I want.

Can someone help me? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:36:45+00:00Added an answer on June 7, 2026 at 6:36 pm

    It sounds like you’ve got a buffering issue with your C++ program; it’s probably not automatically flushing stdout‘s buffers with each line, so all the output “bunches up” until it exits. I know there are some ioctl settings that it could use to change that, but I’ve long since forgotten what they are. A search on “stdout buffering” might bring up something useful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't understand what's going on here: $ node > var f = function()
Here's an extension of the sample node.js code: var express = require('express'); var application
Here is the code I have tried to append a node in existing xml,
I have hourly weather data. I've seen the function examples from here: http://casoilresource.lawr.ucdavis.edu/drupal/node/991 I'm
Here is the code in a function I'm trying to revise. This example works
We are using treepanel in our application.The code is: var exStore = Ext.create('Ext.data.TreeStore',{ root
using jquery-ui-map here is my code $(document).ready(function() {$('#map_canvas').gmap({ 'center': new google.maps.LatLng(3.162456,21.09375), 'zoom': 2, 'streetViewControl':
The following code produces an exception in node.js under windows: var Socket = require(net).Socket;
Here's my node.js file I'm running on Heroku. It works perfectly locally, but when
I have a question when I do the node.js async coding. Here is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.