Skip to content
Snippets Groups Projects
Commit 2f4b3de6 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

SystemCall on Windows now uses ShellExecute for python scripts

parent 86e207ce
No related branches found
No related tags found
No related merge requests found
...@@ -124,12 +124,15 @@ void Msg::Init(int argc, char **argv) ...@@ -124,12 +124,15 @@ void Msg::Init(int argc, char **argv)
char *tmp = getenv("PYTHONPATH"); char *tmp = getenv("PYTHONPATH");
if(tmp){ if(tmp){
path = tmp; path = tmp;
#if defined(WIN32)
path += ";" + split[0];
#else
path += ":" + split[0]; path += ":" + split[0];
#endif
} }
else else
path = split[0]; path = split[0];
setenv("PYTHONPATH", path.c_str(), 1); SetEnvironmentVar("PYTHONPATH", path.c_str());
printf("pythonpath = %s\n", path.c_str());
} }
InitializeOnelab("Gmsh"); InitializeOnelab("Gmsh");
......
...@@ -53,6 +53,15 @@ const char *GetEnvironmentVar(const char *var) ...@@ -53,6 +53,15 @@ const char *GetEnvironmentVar(const char *var)
#endif #endif
} }
const void SetEnvironmentVar(const char *var, const char *val)
{
#if !defined(WIN32)
setenv(var, val, 1);
#else
_putenv((std::string(var) + "=" + std::string(val)).c_str());
#endif
}
double GetTimeInSeconds() double GetTimeInSeconds()
{ {
#if !defined(WIN32) || defined(__CYGWIN__) #if !defined(WIN32) || defined(__CYGWIN__)
...@@ -197,6 +206,25 @@ int KillProcess(int pid) ...@@ -197,6 +206,25 @@ int KillProcess(int pid)
int SystemCall(const std::string &command, bool blocking) int SystemCall(const std::string &command, bool blocking)
{ {
#if defined(WIN32) #if defined(WIN32)
// check if we are trying to execute a Python script
std::string exe, args;
std::string::size_type pos = command.find_first_of(" ");
if(pos != std::string::npos){
exe = command.substr(0, pos);
args = command.substr(pos, command.size() - pos);
}
else exe = command;
int s = exe.size();
if(s > 3 &&
(exe[s-3] == '.') &&
(exe[s-2] == 'p' || exe[s-2] == 'P') &&
(exe[s-1] == 'y' || exe[s-1] == 'Y')){
Msg::Info("Shell opening '%s' with arguments '%s'",
exe.c_str(), args.c_str());
ShellExecute(NULL, (char*)"open", (char*)exe.c_str(),
(char*)args.c_str(), NULL, 0);
}
else{
STARTUPINFO suInfo; STARTUPINFO suInfo;
PROCESS_INFORMATION prInfo; PROCESS_INFORMATION prInfo;
memset(&suInfo, 0, sizeof(suInfo)); memset(&suInfo, 0, sizeof(suInfo));
...@@ -219,6 +247,7 @@ int SystemCall(const std::string &command, bool blocking) ...@@ -219,6 +247,7 @@ int SystemCall(const std::string &command, bool blocking)
NORMAL_PRIORITY_CLASS|DETACHED_PROCESS, NULL, NULL, NORMAL_PRIORITY_CLASS|DETACHED_PROCESS, NULL, NULL,
&suInfo, &prInfo); &suInfo, &prInfo);
} }
}
return 0; return 0;
#else #else
if(!system(NULL)) { if(!system(NULL)) {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <string> #include <string>
const char *GetEnvironmentVar(const char *var); const char *GetEnvironmentVar(const char *var);
void SetEnvironmentVar(const char *var, const char *val);
double GetTimeInSeconds(); double GetTimeInSeconds();
void SleepInSeconds(double s); void SleepInSeconds(double s);
void CheckResources(); void CheckResources();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment