Thread: start a shell in a child witch is waiting

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    4

    Post start a shell in a child witch is waiting

    I want to start a shell oder sqlplus in the child witch execute the commandos from parent
    i dont want to start a new child for each commando or use exec(ls, ... ) each time

    is there a way to solve this ?

    Code:
    
    	if (new_process==0) {
            
    		close(fd[1]);
    
    		while(1)
    		{
    			if(sizeof(readbuffer)>0)
    			nbytes = read(fd[0], readbuffer, sizeof(readbuffer));
    			printf("Read string: %s \n ", readbuffer);
    
    //!!! my problem i dont want to print "ls" all the time i want a shell witch exec ls
    // and all other command the child will get by parent
    
    // my solution is to cread a new child making system("command"); 
    // but i want to run a shell or sqlplus or something else in this process to execute the 
    // parents output
    
    
    		}
    	
    
    
    
    	}
    	if (new_process>0)  {
                    
    
                     // yeah i know its a loop but its the simpelst thing to test without readline stuff
                    char * buf ="ls"
    		close(fd[0]);
    		while (1)
    		{
    
    				write(fd[1], buf, (strlen(buf)+1));
    		}
    
    
    		 }
    
    
    	}

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    You don't have to run a shell in the program. The program is already running in a shell.

    You don't need to start another child to use system("command").

    If you want to send the output back to the parent, use dup2().
    Code:
            dup2(fd[1],1);  /* stdout and stderr to pipe */
            dup2(fd[1],2);
    However, you will need another pipe going the other way to do that, since you cannot really use fd[1].
    Last edited by MK27; 03-02-2009 at 08:54 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    What are you talking about? Why is there a witch waiting for a shellchild? I am sorry, but this is not the correct subforum for voodoo magic.
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  4. #4
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by IceDane View Post
    Why is there a witch [...]? [...] this is not the correct subforum for voodoo magic.
    Well, not technically vodoo, but I believe the solution will involve cauldrons, bird entrails and lots of cackling. :P

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  5. #5
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    Quote Originally Posted by QuantumPete View Post
    Well, not technically vodoo, but I believe the solution will involve cauldrons, bird entrails and lots of cackling. :P

    QuantumPete
    Yes, my thoughts exactly, but I fail to see how voodoo-based sacrifical rituals of young shellchildren relates to C programming.
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  6. #6
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    Quote Originally Posted by IceDane View Post
    Yes, my thoughts exactly, but I fail to see how voodoo-based sacrifical rituals of young shellchildren relates to C programming.
    prepare to be surprised

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    75

    Shell Input output

    deleted msg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cannot start a parameter declaration
    By Dark Nemesis in forum C++ Programming
    Replies: 6
    Last Post: 09-23-2005, 02:09 PM
  2. Linked List Anamoly
    By gemini_shooter in forum C++ Programming
    Replies: 3
    Last Post: 02-28-2005, 05:32 PM
  3. Next Question...
    By Azmeos in forum C++ Programming
    Replies: 3
    Last Post: 06-06-2003, 02:40 PM
  4. Need some help with a basic tic tac toe game
    By darkshadow in forum C Programming
    Replies: 1
    Last Post: 05-12-2002, 04:21 PM