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

标签 c++ c windows winapi

  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()正在用 log.txt 调用 Tail.exe
所有都与调用它的可执行文件位于同一目录中。
收到错误 ENOENT- No such file or directory
此外,指定所有内容的路径,同样的错误。

感谢任何建议,谢谢。

最佳答案

来自您链接的 system() 上的文档:

ENOENT Command interpreter cannot be found.

所以问题不是找不到tail.exe,而是找不到命令解释器。这表明有更大的问题出了问题。我们需要更多信息来诊断真正的问题。同样来自同一页面:

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). If command is NULL, the function simply checks to see whether the command interpreter exists.

这表明了一些调查途径:system(NULL) 返回什么?当您的程序运行时,COMSPECPATH 环境变量的值是多少?

关于c++ - system() 函数找不到可执行文件的可能原因是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2274854/

相关文章:

c++ - 交叉编译和直接在目标上编译时所需的 GCC arm 选项之间的区别?

c++ - 在 C++ 中创建具有随机枚举类型的 Card 对象

c - 将文件指针移至末尾

python - 将 Python 字典转换为类 C 结构

windows - 文本编辑器打开大(巨大的,巨大的,大的)文本文件

c++ - 如何在 Wifi 连接期间以编程方式检测错误的密码输入?

c++ - Visual Studio 2015无法产生在Windows XP上成功注册的ATL Dll

c++ - 安装后CUDA编译报错

c++ - 使用 loadappinit_dlls 注册表项将 dll Hook 到正在运行的进程中

c# - 如何在 Win 7 visual studio 2012 中禁用 C# 中的 #if DEBUG