C programming,very short question?

This is a discussion on C programming,very short question? within the C Programming forums, part of the General Programming Boards category; I have an absolute path to a directory and name of .c file to be compiled and maybe run it ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    333
    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.
    http://www.malcolmmclean.site11.com/www

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, 03:45 PM
  2. Replies: 1
    Last Post: 02-19-2013, 10: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, 05:32 PM
  5. 'short' question
    By sand_man in forum C Programming
    Replies: 5
    Last Post: 03-20-2005, 04:04 PM

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