]> SALOME platform Git repositories - modules/yacs.git/blobdiff - src/runtime/XMLNode.cxx
Salome HOME
Some tests are modified to work in session less mode.
[modules/yacs.git] / src / runtime / XMLNode.cxx
index 6265b5eb68f9b7b29a3959b8e0be90605a4b959b..656f172ed8a74648f4cbea455dfb89f72ededd60 100644 (file)
@@ -1,6 +1,27 @@
+// Copyright (C) 2006-2021  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 #include "XMLNode.hxx"
 #include "XMLPorts.hxx"
 #include "Mutex.hxx"
+#include "TypeCode.hxx"
+#include "AutoLocker.hxx"
 
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
+#ifdef WIN32
+#include <windows.h>
+#include <io.h>
+#define chmod _chmod
+#endif
+#ifdef __APPLE__
+#include <unistd.h> // for mkdtemp
+#endif
+
 //#define _DEVDEBUG_
 #include "YacsTrace.hxx"
 
@@ -50,6 +80,11 @@ void XmlNode::setScript(const std::string& script)
   _script=script;
 }
 
+std::string XmlNode::getScript() const
+{
+  return _script;
+}
+
 std::string XmlNode::getKind() const
 {
   return KIND;
@@ -60,15 +95,26 @@ void XmlNode::execute()
   DEBTRACE("execute");
   char dir[]="yacsXXXXXX";
   // add a lock around mkdtemp (seems not thread safe)
-  MUTEX.lock();
-  char* mdir=mkdtemp(dir);
-  MUTEX.unlock();
-  if(mdir==NULL)
-    {
-      perror("mkdtemp failed");
-      std::cerr << "Problem in mkdtemp " << dir << " " << mdir << std::endl;
-      throw Exception("Execution problem in mkdtemp");
-    }
+  {
+    YACS::BASES::AutoLocker<YACS::BASES::Mutex> alck(&MUTEX);
+#ifdef WIN32
+#ifdef UNICODE
+wchar_t mdir[512 + 1];
+#else
+       char mdir[512 + 1];
+#endif
+    GetTempPath(MAX_PATH+1, mdir);
+    CreateDirectory(mdir, NULL);
+#else
+    char* mdir=mkdtemp(dir);
+#endif
+    if(mdir==NULL)
+      {
+        perror("mkdtemp failed");
+        std::cerr << "Problem in mkdtemp " << dir << " " << mdir << std::endl;
+        throw Exception("Execution problem in mkdtemp");
+      }
+  }
   std::string sdir(dir);
   std::string input=sdir+"/input";
   std::ofstream f(input.c_str());
@@ -96,11 +142,12 @@ void XmlNode::execute()
     run << _ref << "> stdout 2>&1 " << std::endl;
   else
     run << "../"<<_ref << "> stdout 2>&1 " << std::endl;
-  run << "cat stdout" << std::endl;
+  //run << "cat stdout" << std::endl;
   run.close();
   chmod(call.c_str(),00777);
 
-  int ret=system(call.c_str());
+  std::string call2="/bin/sh "+call;
+  int ret=system(call2.c_str());
   if(ret)
     {
       std::cerr << "Problem: " << ret << std::endl;