tor
tor

Reputation: 85

Attach to external c++ process from java process causing issue

I am trying to attach with C++ executable using java.lang.process. The code to build the exec is as under:

int main(int, char**){

std::cout << "Starting Up. . . . . " << std::endl;
std::string command;

while (command != "exit")
{
    std::cin >> command;
}

return 0;
}

While debugging, I found during creation time of process, the process halt on std::cin and expect the value to be entered, but on next iteration it takes the previous 'command' std::cin value automatically and go on iterating the 'while' loop without getting the control back to java process. Why the c++ executable doestnt halt at std::cin at each iteration? I am using Process.getOutputStream() to pass the value from java. Please let me know if any problem with description. Thanks, Tor.

Upvotes: 0

Views: 154

Answers (1)

Torsten Robitzki
Torsten Robitzki

Reputation: 2555

Most likely, there is no valid input or some kind of EOF was simulated. You should check the input for errors:

while ( std::cin && command != "exit" )
{
    std::cin >> command;
}

Upvotes: 1

Related Questions