redirect printf to stdin of aother program [without pipes]

Discussion in 'C' started by adfm, Jan 16, 2009.

  1. adfm

    adfm New Member

    Joined:
    Apr 11, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hello all,

    I have a particular problem to solve. I need to redirect a printf of a program to the stdin of the "system".

    I do not want to pipe the stdin as a child of another program. What I want to do is "simply" override the keyboard and allow any application that has the system focus to catch the printf of my application as a simple keyboard input.

    How can I do this (without pipes)?

    cheers
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Why do you want to do it without pipes, which would seem the logical way to solve this?
     
  3. adfm

    adfm New Member

    Joined:
    Apr 11, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Well, I need it to be application independent. By using pipes I would need to change all applications that may be targets... Which isn't feasible.

    The idea is to have an application that writes to the keyboard buffer, which in turn will be understood as the application that as the focus as the input of any user that is typing the keyboard.

    Cheers
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Probably we're talking about different kinds of pipes. I'm thinking of the vertical bar pipe, i.e. dir | sort, which is implemented at the command line and requires no application modification. The command dir | sort sends the dir output to sort input and the output is a sorted directory (which in its basic form isn't a lot of use because most dir commands include some sorting options anyway, but if sort implements a type of sort that dir doesn't, then this becomes useful).
     
  5. adfm

    adfm New Member

    Joined:
    Apr 11, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    My problem is more complex than that.

    I don't want to redirect raw data from one application to another. What I need is to write an application that writes to the keyboard buffer so that I don't have to explicitly pipe two apps.

    The problem is this. I'm developing a program that will be used along a number of unrelated programs. The idea is to have my application running as a process in background and when something happens it will write to the keyboard buffer and the application that has the focus will catch the keyboard input. For instance an input box of an app will catch the keyboard input of the other. The pipes would only solve my problem if:

    1) I would code both applications to pipe them together as father\son (not the case)
    2) If the second application would just be a simple application that would receive something and handle it (which wont be in most cases).

    I was looking at writing an ISR, but that seems like an overkill to me!

    Any ideas everyone?!

    Cheers
     
  6. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    What operating system are you using?
     
  7. adfm

    adfm New Member

    Joined:
    Apr 11, 2006
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    I'm writing for Linux for starters.

    I know that most likely any implementation wont be portable, so, I'm coding for linux for now.

    I know that for windows I could use VB of C# SendKey function, but my main concern for now is Linux.

    Cheers
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice