Commands

This is a discussion on Commands within the C Programming forums, part of the General Programming Boards category; hello, i am trying to emulate execution of multiple commands like what the shell does. i have some concepts in ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    61

    Commands

    hello, i am trying to emulate execution of multiple commands like what the shell does. i have some concepts in mind and i hope u guys can correct me if im wrong.

    example command: ls -a | sort

    Find out if any piping is needed by looping the string to find "|"
    Set pipeFlag as 1
    Create Pipe // pipe(p)
    Fork
    If Under Parent
    If pipeFlag then
    Close Downstream
    Connect Upstream to pipe (dup2(p[0])
    Close Upstream
    Execute command ls -a
    Wait for child to finish....
    end if
    Else Underchild
    If Pipeflag then
    Close Upstream
    Connect downstream to pipe(dup2(p[1])
    Close downstream
    execute sort
    end if
    else
    execute other commands normally
    i would like some advice on how i could split up the string for the commands. appreciate any help. thanks.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    strtok, strchr are both useful to split strings.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Get user commands from text file.
    By Ironic in forum C Programming
    Replies: 4
    Last Post: 12-08-2008, 10:38 PM
  2. Replies: 2
    Last Post: 07-27-2007, 12:48 PM
  3. Executing system commands cross platform
    By markucd in forum C++ Programming
    Replies: 6
    Last Post: 11-04-2005, 07:56 AM
  4. Disable ALT key commands
    By Lionmane in forum Windows Programming
    Replies: 9
    Last Post: 09-23-2005, 10:41 AM
  5. Bluetooth Dial-up network profile with AT commands
    By BrownB in forum Networking/Device Communication
    Replies: 0
    Last Post: 06-29-2005, 02:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21