c++ - Why does reading from stdout using QProcess break my Windows application? -


i have cross-platform (windows 8/osx 10.10) test application which, part of test, needs spawn child process listen on port (can dynamic or specified). child process (call mockserver), upon startup, send stdout line looks like:

server listening on localhost:50015 

in code spawns mock server, i'm doing this:

//  globals qprocess servermockprocess; qstring serverport  void startservermock() {     servermockprocess.start(server_mock_exe);     servermockprocess.waitforreadyread(2000);     char buf[1024];     qint64 linelength = servermockprocess.readline(buf, sizeof(buf));     qstring output;     int port = 0;     if (linelength != -1) {         output = buf;         std::cout << output << std::endl;          // successful startup produce output looks like:         // server listening on localhost:50015         serverport = output.section(":", -1);         serverport.chop(1); // remove newline         port = serverport.toint();     }      if (!port) {         qstring msg = "couldn't start " server_mock_exe ": " + output;         std::cerr << msg << std::endl;         throw filesystem_exception(msg);     }     std::cout << "talking " << serverport << std::endl; } 

on both platforms, code above appears work - see 2 lines appear when function called, e.g.:

server listening on 127.0.0.1:53869  talking 53869 

subsequently, invoke code cause test application talk server application (using grpc, in case). server_mock_exe can take command line argument specifying port, or if left blank, dynamically chooses 1 (with stdout advertising port). on osx, code works correctly. however, on windows, attempting open grpc connection results in these errors:

e0922 07:43:07.436000000  6420 resolve_address_windows.c:99] getaddrinfo: specified class not found.  d0922 07:43:07.436000000  6420 dns_resolver.c:186] dns resolution failed: retrying in 1.000000000 seconds e0922 07:43:08.440000000  5296 resolve_address_windows.c:99] getaddrinfo: specified class not found.  d0922 07:43:08.441000000  5296 dns_resolver.c:186] dns resolution failed: retrying in 1.773000000 seconds e0922 07:43:10.218000000  1752 resolve_address_windows.c:99] getaddrinfo: specified class not found.  d0922 07:43:10.219000000  1752 dns_resolver.c:186] dns resolution failed: retrying in 2.841000000 seconds 

after experimentation, discovered breaking server reading of stdout port. if instead hard-coded port , passed in, server process communicated with:

void startservermock() {     servermockprocess.start(server_mock_exe " 53869");     servermockprocess.waitforreadyread(2000);     serverport = "53869";     std::cout << "talking " << serverport << std::endl; } 

it isn't dynamic port allocation breaking it, since invoking first version of function line

    servermockprocess.start(server_mock_exe " 53869"); 

instead of leaving blank still results in networking errors above.

any ideas?


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -