diff --git a/Common/GmshSocket.h b/Common/GmshSocket.h index 935745e2df63aee7e3a762f90074818109e78334..1614041a7ff228182511034964a04ad50265f095 100644 --- a/Common/GmshSocket.h +++ b/Common/GmshSocket.h @@ -326,11 +326,11 @@ class GmshServer : public GmshSocket{ public: GmshServer() : GmshSocket(), _portno(-1) {} virtual ~GmshServer(){} - virtual int NonBlockingSystemCall(const char *str) = 0; + virtual int NonBlockingSystemCall(const char *exe, const char *args) = 0; virtual int NonBlockingWait(double waitint, double timeout, int socket=-1) = 0; - // start the client by launching "command" (command is supposed to contain + // start the client by launching "exe args" (args is supposed to contain // '%s' where the socket name should appear) - int Start(const char *command, const char *sockname, double timeout) + int Start(const char *exe, const char *args, const char *sockname, double timeout) { if(!sockname) throw "Invalid (null) socket name"; _sockname = sockname; @@ -395,10 +395,10 @@ class GmshServer : public GmshSocket{ } } - if(command && strlen(command)){ - char cmd[1024]; - sprintf(cmd, command, _sockname.c_str()); - NonBlockingSystemCall(cmd); // starts the solver + if(exe && strlen(exe) && args && strlen(args)){ + char s[1024]; + sprintf(s, args, _sockname.c_str()); + NonBlockingSystemCall(exe, s); // starts the solver } else{ timeout = 0.; // no command launched: don't set a timeout diff --git a/Common/OS.cpp b/Common/OS.cpp index c6a0246f8829175512f198076d098212e64151c5..0572fe5c1ff0c70e8c1abd23c3d11f6b2bc3e61b 100644 --- a/Common/OS.cpp +++ b/Common/OS.cpp @@ -380,22 +380,10 @@ int KillProcess(int pid) return 1; } -int SystemCall(const std::string &command, bool blocking) +int SystemCallExe(const std::string &exe, const std::string &args, bool blocking) { - // separate (potential) executable from arguments - 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; - - // get executable extension - std::vector<std::string> split = SplitFileName(exe); - // do we try to run a .py script, .m script or an .exe? + std::vector<std::string> split = SplitFileName(exe); bool isPython = (split[2] == ".py" || split[2] == ".PY"); bool isOctave = (split[2] == ".m" || split[2] == ".M"); bool isExe = (split[2] == ".exe" || split[2] == ".EXE"); @@ -407,6 +395,10 @@ int SystemCall(const std::string &command, bool blocking) } } + std::string command; + if(exe.size()) command.append("\"" + exe + "\""); + if(command.size() && args.size()) command.append(" " + args); + #if defined(WIN32) && !defined(__CYGWIN__) if(isPython || isOctave){ Msg::Info("Shell opening '%s' with arguments '%s'", exe.c_str(), @@ -474,6 +466,11 @@ int SystemCall(const std::string &command, bool blocking) return 0; } +int SystemCall(const std::string &command, bool blocking) +{ + return SystemCallExe("", command, blocking); +} + std::string GetCurrentWorkdir() { char path[1024]; diff --git a/Common/OS.h b/Common/OS.h index 685005bc47f5fd46db19c47d013f8634adb67e64..808f56fba27482f2e5531c78aea4ef75153d45e4 100644 --- a/Common/OS.h +++ b/Common/OS.h @@ -25,6 +25,7 @@ int KillProcess(int pid); int CreateSingleDir(const std::string &dirName); void CreatePath(const std::string &fullPath); int SystemCall(const std::string &command, bool blocking=false); +int SystemCallExe(const std::string &exe, const std::string &args, bool blocking=false); std::string GetCurrentWorkdir(); void RedirectIOToConsole(); FILE *Fopen(const char* f, const char *mode); diff --git a/Common/gmshLocalNetworkClient.cpp b/Common/gmshLocalNetworkClient.cpp index 6976ee80d04ec58e7a768f194c99ed74ac63087d..b34488a23bffdb248d2b869ac15c1d4cee4121b2 100644 --- a/Common/gmshLocalNetworkClient.cpp +++ b/Common/gmshLocalNetworkClient.cpp @@ -37,9 +37,9 @@ class onelabGmshServer : public GmshServer{ onelabGmshServer(onelab::localNetworkClient *client) : GmshServer(), _client(client) {} ~onelabGmshServer(){} - int NonBlockingSystemCall(const char *str) + int NonBlockingSystemCall(const char *exe, const char *args) { - return SystemCall(str); + return SystemCallExe(exe, args); } int NonBlockingWait(double waitint, double timeout, int socket) { @@ -112,14 +112,13 @@ class onelabGmshServer : public GmshServer{ } std::string exe = FixWindowsPath(_client->getExecutable()); - std::string command; + std::string args; if(exe.size()){ - command.append("\"" + exe + "\""); - std::vector<std::string> args = onelabUtils::getCommandLine(_client); - for(unsigned int i = 0; i < args.size(); i++) - command.append(" " + args[i]); - command.append(" " + _client->getSocketSwitch() + - " \"" + _client->getName() + "\" %s"); + std::vector<std::string> cl = onelabUtils::getCommandLine(_client); + for(unsigned int i = 0; i < cl.size(); i++) + args.append(" " + cl[i]); + args.append(" " + _client->getSocketSwitch() + + " \"" + _client->getName() + "\" %s"); } else{ Msg::Info("Listening on socket '%s'", sockname.c_str()); @@ -127,7 +126,7 @@ class onelabGmshServer : public GmshServer{ int sock; try{ - sock = Start(command.c_str(), sockname.c_str(), + sock = Start(exe.c_str(), args.c_str(), sockname.c_str(), CTX::instance()->solver.timeout); } catch(const char *err){ diff --git a/contrib/onelab/OnelabClients.cpp b/contrib/onelab/OnelabClients.cpp index d11c79cc40ae86e2a430bf1dfa2d2e34114a648c..5650b30de79215a43becf4839845785622e6a9c4 100644 --- a/contrib/onelab/OnelabClients.cpp +++ b/contrib/onelab/OnelabClients.cpp @@ -30,9 +30,9 @@ class onelabMetaModelServer : public GmshServer{ : GmshServer(), _client(client) {} ~onelabMetaModelServer(){} - int NonBlockingSystemCall(const char *str){ - std::cout << "Calling now : " << str << std::endl; - return SystemCall(str); + int NonBlockingSystemCall(const char *exe, const char *args){ + std::cout << "Calling now : " << exe << " " << args << std::endl; + return SystemCall(exe, args); } int NonBlockingWait(double waitint, double timeout, int socket) { @@ -337,7 +337,8 @@ bool localNetworkSolverClient::run() } // Build the commande line - std::string command = buildCommandLine(); + std::string exe = buildCommandLine(); + std::string command(exe); if(command.size()) command.append(appendArguments()); else @@ -350,7 +351,7 @@ bool localNetworkSolverClient::run() int sock; try{ - sock = socketConnection->Start(command.c_str(), sockname.c_str(), 10); + sock = socketConnection->Start(exe.c_str(), command.c_str(), sockname.c_str(), 10); } catch(const char *err){ OLMsg::Error("%s (on socket '%s')", err, sockname.c_str());