Eclipse Debug run and console run of the same prog

2019-06-12 12:56发布

问题:

So this is in reference to my older question which I fixed.

Now the issue is that when I run my program (code as follows)...

#include <stdio.h>
#include <memory.h>

#include <string>
#include <iostream>

using namespace std;

#include "timesync.h"

FILE * CTimeSync::pipe = NULL;

int CTimeSync::TimeSyncCheck()
{
    char szPipeBuffer [200];
    string strPipeOutput;

    memset( szPipeBuffer, 0, sizeof(szPipeBuffer) );

    CTimeSync::pipe = popen( "ntpq -np", "r" );
    if ( CTimeSync::pipe )
    {
        while ( !feof( CTimeSync::pipe ) )
        {
            if ( fgets( szPipeBuffer, 200, CTimeSync::pipe ) != NULL )
            {
//              memset( szPipeBuffer, 0, sizeof(szPipeBuffer) );
                strPipeOutput.append(szPipeBuffer);
            }
        }

        pclose(CTimeSync::pipe);
    }

    cout << strPipeOutput;
    cout << "abc\npqr\nxyz\n123" << endl; //test string
    return 1; //ERROR
}

the run putputs for eclipse debug mode and that in the console (linux) are different.

eclipse run in both eclipse console and redirected to terminal.

     remote           refid          st   t  when poll reach    delay    offset  jitter
abc
pqr
xyz
123

Terminal run (./main)

     remote           refid          st   t  when poll reach    delay    offset  jitter
=======================================================================================
*10.92.1.200       LOCAL(1) ...
abc
pqr
xyz
123

what is causing this?