Results 1 to 3 of 3

Thread: Getting a program to type into another program

  1. #1
    Join Date
    Nov 2012
    Beans
    23

    Getting a program to type into another program

    I have a program, test, in which you need to enter the character 'y', followed by pressing <enter>.
    I have a second program which runs the program, test, in the terminal, but I'm having serious issues of entering the character 'y' (and the enter)...

    This is as close as I've got so far:
    Code:
    #include <stdio.h>
    #include <unistd.h>
    
    int main(void)
    {
        FILE *terminal;
        char *name;
    
        name = ttyname(0);
        terminal = fopen( ttyname(0), "w" );
    
        system( "./test %s", name );
        fprintf( terminal, "y\r" );
    
        fclose(terminal);
    
        return 0;
    }
    - This will run the correct program to the correct terminal, and then print 'y' once you exit the program.
    - Is there any way to get it to type the 'y' in the program (as though you open up the program, then hit 'y' and <enter> on the keyboard)?

    Cheers for any light shed on the issue.

  2. #2
    Join Date
    Aug 2011
    Location
    47°9′S 126°43W
    Beans
    2,172
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: Getting a program to type into another program

    http://jineshkj.wordpress.com/2006/1...child-program/

    Then you write a "y" to the right file descriptor (and don't forget to fflush()).

  3. #3
    Join Date
    Nov 2012
    Beans
    23

    Re: Getting a program to type into another program

    Thanks a lot, I'll look into that.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •