Thread: C programming,very short question?

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    17

    C programming,very short question?

    I have an absolute path to a directory and name of .c file to be compiled and maybe run it if it is possible ? (using gcc like gcc test.c and then ./a.out to run)

    I want to use execlp to run the command and I think before using execlp I need to call :
    Code:
    setenv("PATH", newpath);
    I am new to system programing and I am wondering can someone help me to write that line of code
    Thanks

    Code:
    int execlp(const char *path, const char *arg0, ..., NULL);

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well you seem to have everything you need, short of actually trying it for yourself.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    505
    execlp terminates the calling program, the executes the child. So virtually always you need to call fork(), test that you are in the child branch of the fork(), then call execlp.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C programming,very short question,please help
    By AmirHossein H-m in forum C Programming
    Replies: 1
    Last Post: 02-24-2013, 04:45 PM
  2. Replies: 1
    Last Post: 02-19-2013, 11:30 PM
  3. question on short...
    By raju.b41 in forum C Programming
    Replies: 12
    Last Post: 07-15-2011, 08:34 AM
  4. Replies: 14
    Last Post: 03-08-2010, 06:32 PM
  5. 'short' question
    By sand_man in forum C Programming
    Replies: 5
    Last Post: 03-20-2005, 05:04 PM