/* stderr */\r
if (get_createfile_parameters(key, NSSM_REG_STDERR, path, &sharing, NSSM_STDERR_SHARING, &disposition, NSSM_STDERR_DISPOSITION, &flags, NSSM_STDERR_FLAGS)) return 6;\r
if (path[0]) {\r
- /* Same as stdin? */\r
+ /* Same as stdout? */\r
if (str_equiv(path, stdout_path)) {\r
/* Two handles to the same file will create a race. */\r
if (! DuplicateHandle(GetCurrentProcess(), si->hStdOutput, GetCurrentProcess(), &si->hStdError, 0, true, DUPLICATE_SAME_ACCESS)) {\r
}\r
}\r
\r
+ /* Change to startup directory in case stdout/stderr are relative paths. */\r
+ TCHAR cwd[MAX_PATH];\r
+ GetCurrentDirectory(_countof(cwd), cwd);\r
+ SetCurrentDirectory(service->dir);\r
+\r
/* Try to get stdout and stderr */\r
if (get_output_handles(key, si)) {\r
log_event(EVENTLOG_ERROR_TYPE, NSSM_EVENT_GET_OUTPUT_HANDLES_FAILED, service->name, 0);\r
RegCloseKey(key);\r
+ SetCurrentDirectory(cwd);\r
return 5;\r
}\r
\r
+ /* Change back in case the startup directory needs to be deleted. */\r
+ SetCurrentDirectory(cwd);\r
+\r
/* Try to get throttle restart delay */\r
override_milliseconds(service->name, key, NSSM_REG_THROTTLE, &service->throttle_delay, NSSM_RESET_THROTTLE_RESTART, NSSM_EVENT_BOGUS_THROTTLE);\r
\r