LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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



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

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

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
 
Old 07-13-2005, 02:58 AM   #2
sind
Member
 
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:

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

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
hk_linux
Member
 
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.

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
 
  


Reply


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


All times are GMT -5. The time now is 08:47 AM.

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