Reputation: 85
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
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