Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Common Assumptions

We have three terminals open lets say /dev/pts/x named as terminal-x, where x being 0, 1 and 2.

Shell-Based Scenario

Issue the following command in terminal-2:
cp /dev/pts/1 /dev/pts/0

Now try typing some characters inside the terminal-1 and you observed that some of them (one-yes, one-not pattern) appear in the terminal-0. This means that when you type abcdef the characters ace are displayed in terminal-1 and the characters bdf are displayed in terminal-0.

Programmatic Scenario

I have a text-based console program which I run from terminal-0 and use that terminal for showing status information to user.
Now I want to gather user input (text-based) from terminal-1 by performing by redirecting standard input and output to that console and then performing scanf and printf:

C++
  1  freopen("/dev/pts/1","r", stdin);
  2  freopen("/dev/pts/1","w", stdout);
  3  //And then performing
  4  printf ("enter x");
  5  scanf ("%d", &x);



Summary of Issues


1) When I enter my input string in terminal-1 and press <enter>, it is interpreted as a command and is tried to be executed by the operating system and thus receiving a "command not found".

2) Some of the characters I type in terminal-1 are displayed and some are not!.[however the value is scanf-ed correctly in the program!]


Any kind of advice / suggestion is appreciated in advanced.
Posted
Updated 12-Oct-11 1:50am
v4

1 solution

As far as I am aware, when you login to a terminal the system will automatically start a shell process for the user according to the settings in /etc/passwd, so initial input from that terminal will go to the shell. I am not sure how you could get around this other than replacing the system shell with some program of your own which does not consume the input.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900