LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
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
 
LinkBack Search this Thread
Old 11-11-2003, 05:25 PM   #1
avikosan
LQ Newbie
 
Registered: Jun 2003
Posts: 6

Rep: Reputation: 0
writing to child process stdin


I try to write a program (in C) that fork() a child process and in that child process runs another executable (with execv()) .

I need to write to this child process stdin (the child process waits for input).

I tried to use pipe() to create a pipe between the parent (my) process and the child process, that everything that I write to my stdout goes into the child stdin.

it seems like it has some problem with the newline.

does anybody has an idea ?


Avikosan
 
Old 11-11-2003, 05:51 PM   #2
lenlutz
Member
 
Registered: May 2003
Location: philadelhpia pa
Posts: 92

Rep: Reputation: 15
i have only done this a few thousand times

Named_pipe or MessageQueues....

if you need a few samples, email me......

i dont THINK, you can do what you discribed, since, the pipe must exist,
Before the child starts....(other then with a namedPipe)

Hense grep xyz file | pg
stdout is already directed, Before pg is started (all by shell)

dont give me too much he!!... i could be wrong, but, ive used msgque for years
 
Old 11-11-2003, 07:06 PM   #3
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
1)create a pipe in parent
2)fork child
3)dup2 the read end of pipe in child to stdin dup2(pipefd, STDIN_FILENO)
4)now close the read and write end of the pipe in the child
5)close the read end of the pipe in parent
6)now u have the write end of the pipe in the parent tied to the childs stdin
7)when done, BE SURE TO CLOSE WRITE END OF PIPE IN PARENT else child will never read EOF
8)see here www.1nfamus.netfirms.com for a command shell i wrote if u need more help

peace
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how a father process know which child process send the signal SIGCHLD icoming Programming 10 07-20-2010 07:26 AM
How to kill a Child and all its subsequent child process in C shayer009 Programming 3 12-04-2007 12:40 AM
Killing a child process from another child marri Programming 6 10-01-2004 07:08 PM
Bash Scripting - child process affecting parent process mthaddon Linux - General 1 05-02-2004 01:19 PM
redirect stdin/stdout of running process xtravar Linux - Software 3 03-06-2004 07:54 PM


All times are GMT -5. The time now is 06:14 PM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration