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

treat .exe like .py

parent 64b70a24
No related branches found
No related tags found
No related merge requests found
...@@ -213,7 +213,7 @@ int KillProcess(int pid) ...@@ -213,7 +213,7 @@ int KillProcess(int pid)
int SystemCall(const std::string &command, bool blocking) int SystemCall(const std::string &command, bool blocking)
{ {
// separate executable from arguments // separate (potential) executable from arguments
std::string exe, args; std::string exe, args;
std::string::size_type pos = command.find_first_of(" "); std::string::size_type pos = command.find_first_of(" ");
if(pos != std::string::npos){ if(pos != std::string::npos){
...@@ -226,15 +226,19 @@ int SystemCall(const std::string &command, bool blocking) ...@@ -226,15 +226,19 @@ int SystemCall(const std::string &command, bool blocking)
// get executable extension // get executable extension
std::vector<std::string> split = SplitFileName(exe); std::vector<std::string> split = SplitFileName(exe);
// do we try to run a python script? // do we try to run a .py script or a .exe?
bool script = (split[2] == ".py" || split[2] == ".PY"); bool isPython = (split[2] == ".py" || split[2] == ".PY");
if(script && StatFile(exe)){ bool isExe = (split[2] == ".exe" || split[2] == ".EXE");
Msg::Error("Unable to open file '%s'", exe.c_str());
return 1; if(isPython || isExe){
if(StatFile(exe)){
Msg::Error("Unable to open file '%s'", exe.c_str());
return 1;
}
} }
#if defined(WIN32) #if defined(WIN32)
if(script){ if(isPython){
Msg::Info("Shell opening '%s' with arguments '%s'", exe.c_str(), Msg::Info("Shell opening '%s' with arguments '%s'", exe.c_str(),
args.c_str()); args.c_str());
ShellExecute(NULL, (char*)"open", (char*)exe.c_str(), ShellExecute(NULL, (char*)"open", (char*)exe.c_str(),
...@@ -257,8 +261,8 @@ int SystemCall(const std::string &command, bool blocking) ...@@ -257,8 +261,8 @@ int SystemCall(const std::string &command, bool blocking)
CloseHandle(prInfo.hThread); CloseHandle(prInfo.hThread);
} }
else{ else{
// DETACHED_PROCESS removes the console (useful if the program to launch is // DETACHED_PROCESS removes the console (useful if the program to launch
// a console-mode exe) // is a console-mode exe)
CreateProcess(NULL, (char*)command.c_str(), NULL, NULL, FALSE, CreateProcess(NULL, (char*)command.c_str(), NULL, NULL, FALSE,
NORMAL_PRIORITY_CLASS|DETACHED_PROCESS, NULL, NULL, NORMAL_PRIORITY_CLASS|DETACHED_PROCESS, NULL, NULL,
&suInfo, &prInfo); &suInfo, &prInfo);
...@@ -266,10 +270,14 @@ int SystemCall(const std::string &command, bool blocking) ...@@ -266,10 +270,14 @@ int SystemCall(const std::string &command, bool blocking)
} }
#else #else
std::string cmd(command); std::string cmd(command);
if(script){ if(isPython || isExe){
if(access(exe.c_str(), X_OK)){ if(access(exe.c_str(), X_OK)){
Msg::Info("Script '%s' is not executable: running with python", exe.c_str()); if(isPython){
cmd = "python " + cmd; Msg::Info("Script '%s' is not executable: running with python", exe.c_str());
cmd = "python " + cmd;
}
else
Msg::Warning("File '%s' is not executable", exe.c_str());
} }
else if(split[0].empty()){ else if(split[0].empty()){
// workaround if pwd is not in PATH // workaround if pwd is not in PATH
......
...@@ -412,16 +412,16 @@ int MergeFile(const std::string &fileName, bool warnIfMissing) ...@@ -412,16 +412,16 @@ int MergeFile(const std::string &fileName, bool warnIfMissing)
} }
#endif #endif
#if defined(HAVE_ONELAB) #if defined(HAVE_ONELAB)
else if(ext == ".pro"){ else if(ext == ".pro" || ext == ".PRO"){
int num = defineSolver("GetDP"); int num = defineSolver("GetDP");
std::vector<std::string> split = SplitFileName(fileName);
GModel::current()->setName(split[1] + ".geo"); GModel::current()->setName(split[1] + ".geo");
GModel::current()->setFileName(split[0] + split[1] + ".geo"); GModel::current()->setFileName(split[0] + split[1] + ".geo");
CTX::instance()->launchSolverAtStartup = num; CTX::instance()->launchSolverAtStartup = num;
return 1; return 1;
} }
else if(ext == ".py"){ else if(ext == ".py" || ext == ".PY" ||
int num = defineSolver("python"); ext == ".exe" || ext == ".EXE"){
int num = defineSolver(split[1]);
opt_solver_executable(num, GMSH_SET, fileName); opt_solver_executable(num, GMSH_SET, fileName);
CTX::instance()->launchSolverAtStartup = num; CTX::instance()->launchSolverAtStartup = num;
return 1; return 1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment