简体   繁体   English

在execl()函数ic C语言中使用rm linux命令

[英]use rm linux order in execl() function ic C language

hope to be fine... i'm trying write code that use execl within execl in C language but it's not working when i put the directory of file.希望一切顺利...我正在尝试编写在 C 语言的 execl 中使用 execl 的代码,但是当我放置文件目录时它不起作用。 the code is:代码是:

#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>
 int main(int argc,char* argv[]){
  int n,m,x;
  n=fork();
  if(n==0){
     execl("/bin/rm","rm /home/mazenas/Desktop/folder/","f.txt",NULL);
          }
  else{
     wait(&m);
     printf("end of Programm\n");
      }
  return 0;
  }

help me plaese!帮帮我吧!

The arguments of execl() is specifying the command-line arguments of the program to be executed. execl()的参数指定要执行的程序的命令行参数。

execl("/bin/rm","rm /home/mazenas/Desktop/folder/","f.txt",NULL);

means to execute this:意味着执行这个:

"rm /home/mazenas/Desktop/folder/" "f.txt"

If you want to execute this command:如果要执行此命令:

rm "/home/mazenas/Desktop/folder/f.txt"

You should write:你应该写:

execl("/bin/rm", "rm", "/home/mazenas/Desktop/folder/f.txt", NULL);

I'm pretty sure you mean我很确定你的意思是

 execl("/bin/rm","rm", "/home/mazenas/Desktop/folder/f.txt",NULL);

If rm checks its invocation name, then f.txt makes no sense and it complains;如果rm检查其调用名称,则f.txt没有意义并且它会抱怨; otherwise it's going to try to rm f.txt in the current directory rather than the given path.否则它将尝试在当前目录而不是给定路径中 rm f.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM