Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
07-13-2005, 01:45 AM
|
#1
|
|
Senior Member
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,109
Rep:
|
execute system command in c
Hi i need to execute the following command in c
rm /root/test.log
so i have used the following code
status=execl("/bin/rm","/root/test.log");
fprintf(logfile,"status %d \n",status);
but still this code returns -1 which means failure.. Where am i wrong? Thx
|
|
|
|
07-13-2005, 01:58 AM
|
#2
|
|
Member
Registered: Jun 2005
Posts: 75
Rep:
|
Hi alaios,
Try adding this after the call to execl(), it will tell you what the error was:
Code:
perror("execl() failed");
~sind
|
|
|
|
07-13-2005, 05:02 AM
|
#3
|
|
Senior Member
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,109
Original Poster
Rep:
|
thx but this wont help... this code is being executed by a child so i cant see the error message
|
|
|
|
07-13-2005, 05:26 AM
|
#4
|
|
Member
Registered: Nov 2004
Location: India
Distribution: RedHat, PCQLinux, Fedora
Posts: 95
Rep:
|
1. I think you can use unlink to delete a file. Will it serve your purpose.
Quote:
Extract from man execl.
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.
|
2. The usual syntax i use for execl is
Code:
execl ("/bin/rm", "/bin/rm", "/root/test/log", NULL);
Though i am not sure, if what you do is incorrect.
HTH
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 08:54 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|