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)
返回什么?当您的程序运行时,COMSPEC
和 PATH
环境变量的值是多少?
关于c++ - system() 函数找不到可执行文件的可能原因是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2274854/