简体   繁体   English

system()函数找不到可执行文件的可能原因是什么?

[英]What are the possible reasons the system() function can not find the executable?

  if( system("tail -500 log.txt") == -1)
  {
      //Error calling tail.exe on log 
      //errno is a system macro that expands int returning
      //the last error. strerror() converts the error to it's
      //corresponding error message. 
      printf("Error calling tail.exe with system(): %s",strerror( errno ));

  }

System() is calling Tail.exe with log.txt System()正在使用log.txt调用Tail.exe
All are in the same directory as the executable calling it. 所有文件都与调用它的可执行文件在同一个目录中。
Getting the error ENOENT- No such file or directory 收到错误ENOENT-没有这样的文件或目录
Also, specified paths to everything, same error. 同样,指定所有内容的路径,相同的错误。

Any advice is appreciated, thank you. 任何建议表示赞赏,谢谢。

From the docs on system() that you linked: 从您链接的system()上的文档中:

ENOENT Command interpreter cannot be found. ENOENT找不到命令解释器。

So the problem isn't that it can't find tail.exe, the problem is that it can't find the command interpreter. 因此,问题不在于它找不到tail.exe,而是在于它找不到命令解释器。 This suggests that something larger is going wrong. 这表明更大的事情出了问题。 We'll need more information to diagnose the real problem. 我们将需要更多信息来诊断实际问题。 Also from the same page: 同样在同一页面上:

The system function passes command to the command interpreter, which executes the string as an operating-system command. 系统功能将命令传递给命令解释器,命令解释器将字符串作为操作系统命令执行。 system refers to the COMSPEC and PATH environment variables that locate the command-interpreter file (the file named CMD.EXE in Windows NT and later). 系统指的是COMSPEC和PATH环境变量,这些变量定位命令解释器文件(在Windows NT及更高版本中名为CMD.EXE的文件)。 If command is NULL, the function simply checks to see whether the command interpreter exists. 如果command为NULL,则该函数仅检查命令解释器是否存在。

This suggests a couple of avenues for investigation: What does system(NULL) return? 这建议了一些调查途径: system(NULL)返回什么? And what are the values for the COMSPEC and PATH environment variables when your program runs? 程序运行时, COMSPECPATH环境变量的值是什么?

您可以尝试使用system(“ cmd tail -500 log.txt”)-在某些Windows框上是必需的。

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

相关问题 POSIX SIGBUS 的可能原因是什么? - What are the possible reasons for POSIX SIGBUS? 析构函数调用信号11的可能原因是什么? - What are the possible reasons for signal 11 on destructor call? 复制构造函数中出现异常的可能原因是什么? - What are possible reasons for exception in copy constructors? _tfopen错误22的可能原因是什么? - What are the possible reasons to have an error 22 with _tfopen? 重新编译未更改的C ++文件的目标代码的可能原因是什么? - What can be the possible reasons for the object code of an unchanged C++ file to change on recompilation? 功能退出时分段错误的可能原因 - Possible reasons for segmentation fault on function exit Android设备上二进制文件损坏的可能原因是什么? - What are possible reasons for binary files corruption on android devices `emit dataChanged(...);`不触发视图显示更新的可能原因是什么? - What are the possible reasons for an `emit dataChanged( … );` to not trigger view's display update? 库无法链接到特定体系结构的可能原因? - Possible reasons a library can't link for a specific architecture? 运行可执行文件的 Turbo C++ 系统函数 - Turbo C++ system function running an executable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM