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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
10-31-2004, 04:50 AM
|
#1
|
LQ Newbie
Registered: Oct 2004
Posts: 4
Rep:
|
after redirecting stdin still need to read data from keyboard
hi, i'm a newbie !
please help me on doing the following :
a program (ipm) needs to receive data this way :
ps | ipm
(this command form is a MUST)
so the stdin in <b>ipm</b> will be ONLY what comes from "ps". how do i <b>recreate</b>(?) the stdin in order to read something from the keyboard ?
|
|
|
10-31-2004, 04:54 AM
|
#2
|
Senior Member
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246
Rep:
|
What will be reading from the keyboard? ps doesn't need keyboard input and you say that ipm will ONLY read ps's output....so where would the keyboard input be going?
|
|
|
10-31-2004, 05:00 AM
|
#3
|
LQ Newbie
Registered: Oct 2004
Posts: 4
Original Poster
Rep:
|
ipm needs to receive the process list.
after getting this list, the ipm program should wait for the user to specify a pid (by keyboard) and then kill it, or send some other signal to it.
and the only way that ipm can get the process list is by " ps | ipm " (it's a requirement).
how do i attach keyboard to stdin after this ?
|
|
|
10-31-2004, 05:50 AM
|
#4
|
Senior Member
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246
Rep:
|
I got this to work, but it will only work if you're logged in on pts/1
Code:
itsme@dreams:~/C$ cat inp.c
#include <stdio.h>
#include <string.h>
#include <errno.h>
int main(void)
{
char buf[4096];
while(fgets(buf, sizeof(buf), stdin))
printf("Received: %s", buf);
if(!freopen("/dev/pts/1", "r", stdin))
{
printf("Error reattaching stdin: %s\n", strerror(errno));
return 1;
}
printf("Type something: ");
fflush(stdout);
fgets(buf, sizeof(buf), stdin);
printf("You typed: %s", buf);
return 0;
}
Code:
itsme@dreams:~/C$ ps | ./inp
Received: PID TTY TIME CMD
Received: 1591 pts/1 00:00:00 bash
Received: 2374 pts/1 00:00:00 ps
Received: 2375 pts/1 00:00:00 inp
Type something: it works
You typed: it works
itsme@dreams:~/C$
Last edited by itsme86; 10-31-2004 at 05:51 AM.
|
|
|
10-31-2004, 06:11 AM
|
#5
|
Senior Member
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246
Rep:
|
Here's a solution I found google'ing:
http://<br />
http://www.lugod.org/...032.html<br />
Same concept, except they reattach to /dev/tty instead of /dev/pts/1. I'll leave the rest up to you I'm interested in what you find out though, so if you could post your findings that would be great.
|
|
|
All times are GMT -5. The time now is 02:11 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|