karma_police Posted September 27, 2004 Share Posted September 27, 2004 Im having a some problems using execlp in a c++ program I'm doing, I'm a n00b in Linux C++ programming. The problem is when my app execute the line: int ret = execlp ("ls", "ls", "-c", NULL); My app execute the code until this line and then it just quit, I dont know why. THX Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted September 27, 2004 Share Posted September 27, 2004 Why do you have "ls" twice? First one is the path of the program name and the subsequent arguments are, well, the arguments. You're trying to run ls ls -c Link to comment Share on other sites More sharing options...
0 vcv Posted September 27, 2004 Share Posted September 27, 2004 Why do you have "ls" twice? First one is the path of the program name and the subsequent arguments are, well, the arguments.You're trying to run ls ls -c Wrong. The first argument is the path of what to execute. The second argument is the name you want the new process to spawn as. Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted September 27, 2004 Share Posted September 27, 2004 Wrong.The first argument is the path of what to execute. The second argument is the name you want the new process to spawn as. Well, unless I'm reading this wrong: http://www.die.net/doc/linux/man/man3/execlp.3.html The const char *arg and subsequent ellipses in the execl, execlp, and execle functions can be thought of as arg0, arg1, ..., argn. Together they describe a list of one or more pointers to null-terminated strings that represent the argument list available to the executed program. The first argument, by convention, should point to the file name associated with the file being executed. The list of arguments must be terminated by a NULL pointer. Link to comment Share on other sites More sharing options...
0 vcv Posted September 27, 2004 Share Posted September 27, 2004 The const char *arg and subsequent ellipses in the execl, execlp, and execle functions can be thought of as arg0, arg1, ..., argn. Together they describe a list of one or more pointers to null-terminated strings that represent the argument list available to the executed program. The first argument, by convention, should point to the file name associated with the file being executed. The list of arguments must be terminated by a NULL pointer.Thanks. Link to comment Share on other sites More sharing options...
0 karma_police Posted September 27, 2004 Author Share Posted September 27, 2004 Yes I corrected the typo but that wasnt the problem, thx. The problem was that a child process was still running, I'm learning threads, forks, etc. THX Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted September 27, 2004 Share Posted September 27, 2004 Thanks. Somehow I just glazed over that part and it never sunk in.... But yeah, it makes sense as the first argument in argv is always the name of the program, but somehow since I ignored that I figured the first argument would be argv[0] :pinch: You can tell I don't use execlp much, I use system() more.... *Goes to bed* :wacko: Link to comment Share on other sites More sharing options...
Question
karma_police
Im having a some problems using execlp in a c++ program I'm doing, I'm a n00b in Linux C++ programming.
The problem is when my app execute the line:
int ret = execlp ("ls", "ls", "-c", NULL);My app execute the code until this line and then it just quit, I dont know why.
THX
Link to comment
Share on other sites
6 answers to this question
Recommended Posts