Jump to content

How to change default stdin to a process

- - - - -

  • Please log in to reply
1 reply to this topic

#1
sudheer2510

sudheer2510

    Newbie

  • Members
  • Pip
  • 1 posts
Hi,

I have two processes (one written in tcl (wish process) and the other is a C Program (a.out))
I am opening the second process as a sub process from wish process by using pipe as follows

set pipe [open "| sh -c { $execCommand } " r+ ]

So, when i want to send a message to process 2, i can use "puts $pipe <message>" and the message can be received at process2 at fd 0 . i.e., "read(0,buff,size) in process2"

Now my query is "How to change that default fd 0 at receiving side? i.e., I want to receive the message when I give read((5,buff,size)) on process2???"

Thanks in Advance,
rAzoRbaCK

#2
fayyazlodhi

fayyazlodhi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 403 posts
You need to use (in linux c)


 #include <unistd.h>

  int dup2(int fildes, int fildes2);


It basically copies param1 descriptors into param2 after closing the param2 from file descriptor table if opened previously.

So something like

   if (dup2(your_fildes, STDIN_FILENO) == -1) {


      printf("Failed to redirect standard input");


   }


would do the job




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users