Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   redirect printf to stdin of aother program [without pipes] (http://www.go4expert.com/forums/redirect-printf-stdin-aother-program-t15843/)

adfm 16Jan2009 22:12

redirect printf to stdin of aother program [without pipes]
 
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

xpi0t0s 17Jan2009 00:47

Re: redirect printf to stdin of aother program [without pipes]
 
Why do you want to do it without pipes, which would seem the logical way to solve this?

adfm 17Jan2009 03:56

Re: redirect printf to stdin of aother program [without pipes]
 
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

xpi0t0s 17Jan2009 14:38

Re: redirect printf to stdin of aother program [without pipes]
 
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).

adfm 19Jan2009 18:44

Re: redirect printf to stdin of aother program [without pipes]
 
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

xpi0t0s 19Jan2009 18:53

Re: redirect printf to stdin of aother program [without pipes]
 
What operating system are you using?

adfm 19Jan2009 19:37

Re: redirect printf to stdin of aother program [without pipes]
 
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


All times are GMT +5.5. The time now is 23:34.