LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-06-2006, 02:28 AM   #1
socialjazz
LQ Newbie
 
Registered: Sep 2006
Posts: 9

Rep: Reputation: 0
How to pass system(cmd) into a specific process?


Lets say i have a simple program

void main(void)
{
key = read_key();
if (key == 'q')
printf ("q is pressed\n");
else
printf ("not q is pressed\n");
}

read_key() will detect a key pressed in the console.

I execute this application by using system(app_name);
I also know the PID (process ID) of this app running

how do i use C programming to simulate a key pressed in the application running?

Note that i only invoke the application to run by using the shell command system(app_name).
 
Old 10-06-2006, 05:00 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by socialjazz
read_key() will detect a key pressed in the console.
how does it detect a keypress ?
Quote:
I execute this application by using system(app_name);
I also know the PID (process ID) of this app running

how do i use C programming to simulate a key pressed in the application running?
The simpler way would be by having read_key() to support an alternative input method.
 
Old 10-06-2006, 11:35 PM   #3
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
You have to use popen("appname","w") instead of system("appname"). Then with the handle returned by popen() you can fwrite() the keypress to the process's stdin. Call pclose() when done.

Edit: this may also work though I haven't tried it.
Try calling system("echo X | appname");
I'd be surprised if it doesn't work.

Last edited by randyding; 10-06-2006 at 11:38 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
get info about a specific process hfawzy Programming 4 01-31-2007 01:11 PM
Planning to change root pass and oracle system pass sathyguy Red Hat 1 12-20-2005 09:53 PM
pass locale info to a specific application? Peff Linux - Software 2 06-24-2005 04:40 AM
Want to limit Memory to a specific Process tstaples Linux - General 3 01-26-2005 01:59 PM
load specific process watching? Artanicus Linux - General 2 01-16-2005 02:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration