[英]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? 程序运行时,
COMSPEC
和PATH
环境变量的值是什么?
您可以尝试使用system(“ cmd tail -500 log.txt”)-在某些Windows框上是必需的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.