views:

68

answers:

2
  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, thank you.

+5  A: 

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?

JSBangs
I completely missed that, thanks, at least I'm on the right path now...thanks
Tommy
Looks like they are the same running or not. COMSPEC path looks right: C:\WINDOWS\System32\cmd.exe However, PATH is pointing to a directory from a random application on my PC. What is PATH suppose to be? System(NULL) = 0
Tommy
Are you perchance running on a 64-bit system? If so, depending on the binaries that you have you might need to use the Wow64 COMSPEC.
JSBangs
@Tommy: `%PATH%` is a list of directories of applications. It's quite possible there's only one entry. Most applications are started via the start menu links, not the command line, and therefore those apps don't appear in `%PATH%`
MSalters
+1  A: 

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

Liz Albin
same error, thanks though.
Tommy
Then have you created a working program that calls system? Try that, if you haven't yet.
Liz Albin