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

trying to fix onelab clients with whitespace, take 2 :-(

parent e8158bce
Branches
Tags
No related merge requests found
......@@ -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
......
......@@ -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];
......
......@@ -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);
......
......@@ -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){
......
......@@ -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());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment