Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 07-13-2005, 02:45 AM   #1
Senior Member
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Rep: Reputation: 45
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

fprintf(logfile,"status %d \n",status);

but still this code returns -1 which means failure.. Where am i wrong? Thx
Old 07-13-2005, 02:58 AM   #2
Registered: Jun 2005
Posts: 75

Rep: Reputation: 15
Hi alaios,

Try adding this after the call to execl(), it will tell you what the error was:

perror("execl() failed");
Old 07-13-2005, 06:02 AM   #3
Senior Member
Registered: Jan 2003
Location: Aachen
Distribution: Opensuse 11.2 (nice and steady)
Posts: 2,203

Original Poster
Rep: Reputation: 45
thx but this wont help... this code is being executed by a child so i cant see the error message
Old 07-13-2005, 06:26 AM   #4
Registered: Nov 2004
Location: India
Distribution: RedHat, PCQLinux, Fedora
Posts: 95

Rep: Reputation: 15
1. I think you can use unlink to delete a file. Will it serve your purpose.

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

execl ("/bin/rm", "/bin/rm",  "/root/test/log", NULL);
Though i am not sure, if what you do is incorrect.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
execute system command from c alaios Programming 2 07-19-2005 08:45 AM
remote command execute telnet with 1 command MPowers Linux - Networking 2 06-30-2005 07:31 AM
command execute without ./ kaon Slackware 11 09-15-2004 06:14 PM
Execute a command as another user mpgram Linux - Newbie 6 06-09-2004 12:45 AM
Execute Command lawrencegoodman Linux - Newbie 2 10-23-2003 09:36 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:44 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration