开发者

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

All are in the same directory as the executable calling it.

Getting the error ENOENT- No such file or directory

Also, specified paths to everything, same error.

Any advice is appreciated, t开发者_高级运维hank you.


From the docs on system() that you linked:

ENOENT Command interpreter cannot be found.

So the problem isn't that it can't find tail.exe, the problem is that it can't find the command interpreter. 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). If command is NULL, the function simply checks to see whether the command interpreter exists.

This suggests a couple of avenues for investigation: What does system(NULL) return? And what are the values for the COMSPEC and PATH environment variables when your program runs?


You might try system("cmd tail -500 log.txt") - that's been necessary on some windows boxes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜