LocalProcess.patch

Abdelghani Omari, 09/27/2018 01:04 PM

Download (3.76 KB)

View differences:

LocalProcess.cpp (working copy)
66 66
#endif
67 67

  
68 68
#ifdef PLATFORM_WIN32
69
bool Win32CreateProcess(const char *command, const char *envptr, STARTUPINFOW& si, PROCESS_INFORMATION& pi)
69
bool Win32CreateProcess(const char *command, const char *envptr, STARTUPINFOW& si, PROCESS_INFORMATION& pi, const char *processWorkDirectory)
70 70
{ // provides conversion of charset for cmdline and envptr
71 71
	WString wcmd(command);
72
	WString wpwd(processWorkDirectory);
72 73
	int n = wcmd.GetCount() + 1;
73 74
	Buffer<wchar> cmd(n);
74 75
	memcpy(cmd, wcmd, n * sizeof(wchar));
......
84 85
		memcpy(env, wenv, (len + 2) * sizeof(wchar));
85 86
	}
86 87
#endif
87
	return CreateProcessW(NULL, cmd, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, (void *)envptr, NULL, &si, &pi);
88
	return CreateProcessW(NULL, cmd, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, (void *)envptr, wpwd, &si, &pi);
88 89
}
89 90
#endif
90 91

  
91
bool LocalProcess::DoStart(const char *command, const Vector<String> *arg, bool spliterr, const char *envptr)
92
bool LocalProcess::DoStart(const char *command, const Vector<String> *arg, bool spliterr, const char *envptr, const char *processWorkDirectory)
92 93
{
93 94
	LLOG("LocalProcess::Start(\"" << command << "\")");
94 95

  
......
173 174
	    }
174 175
		command = cmdh;
175 176
	}
176
	bool h = Win32CreateProcess(command, envptr, si, pi);
177
	bool h = Win32CreateProcess(command, envptr, si, pi, processWorkDirectory);
177 178
	LLOG("CreateProcess " << (h ? "succeeded" : "failed"));
178 179
	CloseHandle(hErrorWrite);
179 180
	CloseHandle(hInputRead);
......
338 339
		LLOG("[" << a << "]: <" << (args[a] ? args[a] : "NULL") << ">");
339 340
#endif//DO_LLOG
340 341

  
342
	if(processWorkDirectory)
343
		chdir(processWorkDirectory);
341 344
	LLOG("running execve, app = " << app << ", #args = " << args.GetCount());
342 345
	if(envptr) {
343 346
		const char *from = envptr;
LocalProcess.h (working copy)
58 58

  
59 59
	typedef LocalProcess CLASSNAME;
60 60

  
61
	bool DoStart(const char *cmdline, const Vector<String> *arg, bool spliterr, const char *envptr = NULL);
61
	bool DoStart(const char *cmdline, const Vector<String> *arg, bool spliterr, const char *envptr = NULL, const char *processWorkDirectory = NULL);
62 62

  
63 63
public:
64
	bool Start(const char *cmdline, const char *envptr = NULL)        { return DoStart(cmdline, NULL, false, envptr); }
65
	bool Start2(const char *cmdline, const char *envptr = NULL)       { return DoStart(cmdline, NULL, true, envptr); }
64
	bool Start(const char *cmdline, const char *envptr = NULL, const char *processWorkDirectory = NULL)        { return DoStart(cmdline, NULL, false, envptr, processWorkDirectory); }
65
	bool Start2(const char *cmdline, const char *envptr = NULL, const char *processWorkDirectory = NULL)       { return DoStart(cmdline, NULL, true, envptr, processWorkDirectory); }
66 66

  
67
	bool Start(const char *cmd, const Vector<String>& arg, const char *envptr = NULL)        { return DoStart(cmd, &arg, false, envptr); }
68
	bool Start2(const char *cmd, const Vector<String>& arg, const char *envptr = NULL)       { return DoStart(cmd, &arg, true, envptr); }
67
	bool Start(const char *cmd, const Vector<String>& arg, const char *envptr = NULL, const char *processWorkDirectory = NULL)        { return DoStart(cmd, &arg, false, envptr, processWorkDirectory); }
68
	bool Start2(const char *cmd, const Vector<String>& arg, const char *envptr = NULL, const char *processWorkDirectory = NULL)       { return DoStart(cmd, &arg, true, envptr, processWorkDirectory); }
69 69
	
70 70
#ifdef PLATFORM_POSIX
71 71
	LocalProcess& DoubleFork(bool b = true)                           { doublefork = b; return *this; }