繁体   English   中英

Execlp C脚本错误

[英]Execlp C Script Error

因此,我有一个尝试运行的脚本。 我有这行代码:

execlp("find","find","-name",cmdCommands,"-exec","stat","--format","\"%A %s %x %w\"","{} \\;",NULL);

那行给我这个错误

find: missing argument to '-exec'

我猜是"{} \\\\;" 是问题。 我更改为"{}","\\\\;" 但我仍然遇到相同的错误。

我必须修改才能工作。

cmdCommands是一个char 我在子进程中使用execlp

主要问题是您将stat命令及其参数传递为find命令的不同参数。 stat命令及其所有参数是find命令的单个参数。

因此将通话更改为

execlp("find", "find", "-name", cmdCommands, "-exec",
       "stat --format \"%A %s %x %w\" {}", ";", NULL);

您要使用:

  execlp("find", "find", 
    ".", /* Replace by path to search through. */ 
    "-name", cmdCommands, 
    "-exec", "stat", "--format=\"%A %s %x %w\"", "{}", ";", 
    (char*) NULL /* The cast is mandatory to stay portable. */
  );

暂无
暂无

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

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