Link to home
Start Free TrialLog in
Avatar of karana
karana

asked on

i/o for terminals

sir ,


 **********     1.c *********

        int main()
               {
                  write(0 ,"ratheesh" ,8);
                 }

this program will output   : ratheesh on terminal
in which it is executed .

There r 3 terminals i hve opened on my p3 system
working on RedHat 8 os.

tty1  , tty2 ,tty3 .

Is there any method to change output from terminal to other without  using like the below
          int a =open("/dev/tty2" ,O_WRONLY);



Avatar of Alf666
Alf666

First of all, I would not write the the file descriptor 0. 0 is stdin (the input buffer). You should write to stdout (1) or stderr (2).

But there is no other way than the one you're mentioning, except using shell redirection :

echo "foo" > /dev/tty2

ASKER CERTIFIED SOLUTION
Avatar of ray_pro2
ray_pro2

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Urgl !!! Oh no :-))) NOT system().

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry forgot to show the includes.

#include <stdio.h> /* perror */
#include <unistd.h> /* write*/
#include <fcntl.h>
#include <sys/types.h>