extern const char* shar_config;
extern const char* shar_prefix;
extern bool shar_checkonly;
+extern bool shar_version;
// internal variables
SERVICE_STATUS ssStatus; // current status of the service
char szErr[256];
LPCSTR lpszInstall = nullptr;
LPCSTR lpszRemove = nullptr;
+LPCSTR lpszStdout = nullptr;
+LPCSTR lpszStderr = nullptr;
// internal function prototypes
VOID WINAPI service_ctrl(DWORD dwCtrlCode);
}
else if (_stricmp("stdout", argv[i]+1) == 0)
{
- if (argc > ++i)
- freopen(argv[i++], "a+", stdout);
+ if (argc > ++i) {
+ lpszStdout = argv[i++];
+ freopen(lpszStdout, "a+", stdout);
+ }
}
else if (_stricmp("stderr", argv[i]+1) == 0)
{
- if (argc > ++i)
- freopen(argv[i++], "a+", stderr);
+ if (argc > ++i) {
+ lpszStderr = argv[i++];
+ freopen(lpszStderr, "a+", stderr);
+ }
}
else if (_stricmp( "console", argv[i]+1) == 0)
{
{
i++;
bConsole = TRUE;
- shar_checkonly=true;
+ shar_checkonly = true;
+ }
+ else if (_stricmp( "version", argv[i]+1) == 0)
+ {
+ i++;
+ bConsole = TRUE;
+ shar_version = true;
}
else if (_stricmp( "config", argv[i]+1) == 0)
{
printf("%s -remove <name> to remove the named service\n", argv[0]);
printf("%s -console to run as a console app for debugging\n", argv[0]);
printf("%s -check to run as a console app and check configuration\n", argv[0]);
+ printf("%s -version to run as a console app and print the version\n", argv[0]);
printf("\t-stdout <path> to redirect stdout stream\n");
printf("\t-stderr <path> to redirect stderr stream\n");
printf("\t-prefix <dir> to specify the installation directory\n");
cmd = cmd + " -config " + shar_config;
if (shar_schemadir)
cmd = cmd + " -schemadir " + shar_schemadir;
+ if (lpszStdout)
+ cmd = cmd + " -stdout " + lpszStdout;
+ if (lpszStderr)
+ cmd = cmd + " -stderr " + lpszStderr;
schSCManager = OpenSCManager(
nullptr, // machine (nullptr == local)