calling shellscript from c

This is a discussion on calling shellscript from c within the C Programming forums, part of the General Programming Boards category; I wonder if there ir a way to call shellscript from a c program. I want to use some comands ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Location
    japan
    Posts
    126

    calling shellscript from c

    I wonder if there ir a way to call shellscript from a c program.
    I want to use some comands like ls and grep and rm from my c program how can i do this?
    (I know that for creating directories there is a mkdir function in C. Are there any likely functions in C, specially for removing files.)
    Thanks in advance.
    Mac OS 10.6 Snow Leopard : Darwin

  2. #2
    Registered User
    Join Date
    Aug 2006
    Posts
    90
    use system()

  3. #3
    Registered User
    Join Date
    Nov 2006
    Location
    japan
    Posts
    126
    thanks cnu_sree.
    now i know.
    Mac OS 10.6 Snow Leopard : Darwin

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    6
    Thanks for the valuable tip there dude! I never knew this function existed in Turbo C

  5. #5
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    remove(file_name) will erase a file.

  6. #6
    Dragon Rider jas_atwal's Avatar
    Join Date
    Nov 2007
    Location
    India
    Posts
    54
    Quote Originally Posted by cnu_sree View Post
    use system()
    That surely is an excellent command to start with. But as it invokes a new shell to execute a command, it may be slow to execute.
    Instead you should functions from unistd.h
    -------------------------------------------------------------------
    There are 10 kinds of people in this world....Those who understand binary and those who don't

  7. #7
    Registered User
    Join Date
    Nov 2007
    Posts
    2
    What about execl() and execlp() under unix

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stack issues when calling a COM library
    By notnot in forum C Programming
    Replies: 3
    Last Post: 06-01-2009, 03:12 AM
  2. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  3. calling default instead of argument constructor, why?!
    By cppn00b in forum C++ Programming
    Replies: 6
    Last Post: 01-30-2005, 04:24 AM
  4. calling conventions
    By Micko in forum C Programming
    Replies: 2
    Last Post: 07-18-2004, 10:13 AM
  5. Question on function syntax and calling function
    By cbrman in forum C Programming
    Replies: 10
    Last Post: 10-05-2003, 06:32 PM

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