+ UNDER_LOCK( cout << "*** exec_command = " << exec_command << endl );
+
+
+ // Create the environment for the new process. Note (RB): Here we change the environment for
+ // the process launched in local. It would seem more logical to set the environment for the
+ // remote process.
+ // Note that if no environment is specified, we reuse the current environment.
+ Environnement env = _job.getEnvironnement();
+ char * chNewEnv = NULL;
+
+ if(env.size() > 0) {
+ chNewEnv = new char[4096];
+ LPTSTR lpszCurrentVariable = chNewEnv;
+ for(Environnement::const_iterator it=env.begin() ; it!=env.end() ; it++) {
+ const string & key = (*it).first;
+ const string & value = (*it).second;
+ string envvar = key + "=" + value;
+ envvar.copy(lpszCurrentVariable, envvar.size());
+ lpszCurrentVariable[envvar.size()] = '\0';
+ lpszCurrentVariable += lstrlen(lpszCurrentVariable) + 1;
+ }
+ // Terminate the block with a NULL byte.
+ *lpszCurrentVariable = '\0';
+ }
+
+
+ STARTUPINFO si;
+ ZeroMemory( &si, sizeof(si) );
+ si.cb = sizeof(si);
+ ZeroMemory( &pi, sizeof(pi) );
+
+ // Copy the command to a non-const buffer
+ size_t str_size = exec_command.size();
+ char buffer[str_size+1];
+ exec_command.copy(buffer,str_size);
+ buffer[str_size]='\0';
+
+ // launch the new process
+ BOOL res = CreateProcess(NULL, buffer, NULL, NULL, FALSE,
+ 0, chNewEnv, NULL, &si, &pi);
+
+ if (!res) throw RunTimeException("Error while creating new process");
+
+ CloseHandle(pi.hThread);
+
+ } catch (GenericException & e) {
+
+ std::cerr << "Caught exception : " << e.type << " : " << e.message << std::endl;
+ }
+
+ return pi.hProcess;
+ }
+
+#endif