console input breaks stty terminal

Questions about Wine on Linux
Locked
mariusm
Newbie
Newbie
Posts: 3
Joined: Wed Oct 08, 2014 7:39 am

console input breaks stty terminal

Post by mariusm »

Hi,

I am trying to improve my program by preventing a console from closing after my program is finished so that user can see that it is a console program and needs to be run from command prompt.
My method is to add cin.get() (or getchar()) before exit.
My problem is that when I test my program on Linux with wine, it messes up the terminal so that further user input is no longer visible. stty shows these extra options which where not present before:

Code: Select all

-brkint -icrnl
-icanon -iexten -echo
As you can see it has -echo and some more.

If I don't do cin.get(), then everything is fine.

Here is my minimal example enter.cpp:

Code: Select all

#include <iostream>
int main(int argc, char* args[]) {
  std::cout << "Press ENTER" << std::endl;
  std::cin.get();
  std::cout << std::endl;
  return 0;
}
I compile it like this:
i686-w64-mingw32-g++ -m32 -mconsole -static enter.cpp -o enter.exe

Then run it like this:
wine ./enter.exe

afterwards the terminal is unusable as the user input is not visible.
thus I need to reset my terminal with reset command.

So my questions are:
1) why cin.get() and getchar() in wine modify stty?
2) is there a better way of stopping console from closing?

For now I made a bash script wrapper around wine to restore stty, but this is not acceptable.
mvk
Newbie
Newbie
Posts: 3
Joined: Tue Oct 06, 2015 8:28 am

Re: console input breaks stty terminal

Post by mvk »

I experienced a very similar problem. I just posted the solution that worked for me in another thread:
viewtopic.php?f=2&t=20028

Hoping to be of assistance to those googlers after me.
mariusm
Newbie
Newbie
Posts: 3
Joined: Wed Oct 08, 2014 7:39 am

Re: console input breaks stty terminal

Post by mariusm »

thanks @mvk for the good news about it being fixed in 1.7.51.
Unfortunately I would have to wait for Debian to catch up with 1.7 branch of wine (currently it distributes 1.6.2), so perhaps the fix could be backported to 1.6.2.
For now, I could not find the exact fix/patch (perhaps it got fixed earlier or by implementing something else).
User avatar
dimesio
Moderator
Moderator
Posts: 13367
Joined: Tue Mar 25, 2008 10:30 pm

Re: console input breaks stty terminal

Post by dimesio »

Debian packages the development branch. https://www.winehq.org/download/debian
mariusm
Newbie
Newbie
Posts: 3
Joined: Wed Oct 08, 2014 7:39 am

Re: console input breaks stty terminal

Post by mariusm »

Thanks dimesio, that was very helpful, I did not know that.
I tried wine32-development (1.7.51-1 from testing and 1.7.52-1 from unstable) and both of them have the same symptoms (adds -echo and others to stty configuration).
So my conclusion is that the problem is still there.
Locked