5 Replies - 3038 Views - Last Post: 19 January 2009 - 08:51 AM Rate Topic: -----

#1 adfm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-January 09

redirect printf to stdin of aother program [without pipes]

Post icon  Posted 16 January 2009 - 09:51 AM

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

Is This A Good Question/Topic? 0
  • +

Replies To: redirect printf to stdin of aother program [without pipes]

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: redirect printf to stdin of aother program [without pipes]

Posted 16 January 2009 - 10:02 AM

Whatever method you use it will probably be platform specific.

There are several directions here: #1 programatically piping -- One program calls another and feeds its stout to the other program's stdin. Basically this is the same as creating a pipe from the command line though it can give you more control (since you can turn the pipe on and off or even pipe to multiple programs).

Another route is (in windows at least) the SendKeys method. Here you are literally emulating a keyboard.

There are actually quite a number of ways to get two processes to talk to one another. Some would be easy to do in a platform independent way but most will require a platform specific solution.
Was This Post Helpful? 0
  • +
  • -

#3 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: redirect printf to stdin of aother program [without pipes]

Posted 16 January 2009 - 10:07 AM

after rereading your post the sendkeys method seems to be what you want. This is terribly easy in windows but I have no expiance with it linux.

Search our forum for "sendkeys" and you will find plenty of examples. Also just google for it. MSDN is a great resource as well.

In Linux I believe that there are some Xlib functions but I think it is better to look at the KDE/GNOME APIs before resorting to the XLib -- but I will let a linux programmer make comment as I have no experience with this.
Was This Post Helpful? 0
  • +
  • -

#4 adfm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-January 09

Re: redirect printf to stdin of aother program [without pipes]

Posted 16 January 2009 - 10:09 AM

Yep, I know, but I don't want to talk to a particular program.

The idea is to have an app that is reading a hw device and when it reads something, it "prints" to the keyboard and any application that has focus (notepad for instance) would just see that as the keyboard being pounded by the user.

I was just reading about installing an interrupt handler for the keyboard, but I have to check if I can do that in teh same way in Linux and Win32.

Anyhow... this seems like overkill :S

Thanks for the reply ;)

cheers

This post has been edited by adfm: 16 January 2009 - 10:11 AM

Was This Post Helpful? 0
  • +
  • -

#5 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: redirect printf to stdin of aother program [without pipes]

Posted 16 January 2009 - 10:28 AM

Well... since both windows and Linux provide "SendKeys" type functionality (you don't have to select a particular program to send keys to) then you should be able to build a standard interface -- once you have that then it is not so hard create a platform independent version of your program.

Another solution would be to use a different language such as REXX -- Scripting languages -- let the language worry about platform independence. You can find this sendkeys functionality in a number of scripting languages.
Was This Post Helpful? 0
  • +
  • -

#6 adfm  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-January 09

Re: redirect printf to stdin of aother program [without pipes]

Posted 19 January 2009 - 08:51 AM

yep, but the problem is... and what if the application will only run on console without X? All of the scripts and examples I saw rely on X to know to whom to send the key and interpret the keystrokes!

I am stuck!

HELP! ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1