T.T*_*.T. 1 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 ));
}
Run Code Online (Sandbox Code Playgroud)
System()使用log.txt调用Tail.exe
All与调用它的可执行文件位于同一目录中.
获取错误ENOENT-没有这样的文件或目录
另外,指定所有内容的路径,相同的错误.
任何建议表示赞赏,谢谢.
从system()您链接的文档:
ENOENT无法找到命令解释程序.
所以问题不在于它找不到tail.exe,问题在于它无法找到命令解释器.这表明更大的事情是错误的.我们需要更多信息来诊断真正的问题.同样来自同一页面:
系统函数将命令传递给命令解释器,命令解释器将字符串作为操作系统命令执行.system是指定位命令解释程序文件(Windows NT及更高版本中名为CMD.EXE的文件)的COMSPEC和PATH环境变量.如果command为NULL,则该函数只检查命令解释器是否存在.
这表明有几种调查途径:什么system(NULL)回归?程序运行时COMSPEC,PATH环境变量的值是多少?