Skip to content

Instantly share code, notes, and snippets.

@orzFly
Created April 4, 2014 14:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orzFly/9976088 to your computer and use it in GitHub Desktop.
Save orzFly/9976088 to your computer and use it in GitHub Desktop.
very simple "which" alternative for Windows
#include <stdio.h>
#include <windows.h>
int main(int argc, char **argv)
{
if (argc == 2)
{
char path[MAX_PATH];
HINSTANCE ret = FindExecutable(argv[1], 0, path);
if ((int)ret > 32)
puts(path);
else
{
fprintf(stderr, "WHICH: cannot found %s (FindExecutable returned %d)\n", argv[1], ret);
return 1;
}
}
else
{
printf("Finds first or all executables on path, or which executable is associated with a document file or extension.\n\nWHICH command\n\n command - Command name.\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment