PostProcessor.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "PostProcessor.hpp"
  2. namespace Slic3r {
  3. #ifdef WIN32
  4. //FIXME Ignore until we include boost::process
  5. void run_post_process_scripts(const std::string &path, const PrintConfig &config)
  6. {
  7. }
  8. #else
  9. #include <boost/process/system.hpp>
  10. void run_post_process_scripts(const std::string &path, const PrintConfig &config)
  11. {
  12. if (config.post_process.values.empty())
  13. return;
  14. config.setenv_();
  15. for (std::string script: config.post_process.values) {
  16. // Ignore empty post processing script lines.
  17. boost::trim(script);
  18. if (script.empty())
  19. continue;
  20. BOOST_LOG_TRIVIAL(info) << "Executing script " << script << " on file " << path;
  21. if (! boost::filesystem::exists(boost::filesystem::path(path)))
  22. throw std::runtime_exception(std::string("The configured post-processing script does not exist: ") + path);
  23. #ifndef WIN32
  24. file_status fs = boost::filesystem::status(path);
  25. //FIXME test if executible by the effective UID / GID.
  26. // throw std::runtime_exception(std::string("The configured post-processing script is not executable: check permissions. ") + path));
  27. #endif
  28. int result = 0;
  29. #ifdef WIN32
  30. if (boost::iends_with(file, ".gcode")) {
  31. // The current process may be slic3r.exe or slic3r-console.exe.
  32. // Find the path of the process:
  33. wchar_t wpath_exe[_MAX_PATH + 1];
  34. ::GetModuleFileNameW(nullptr, wpath_exe, _MAX_PATH);
  35. boost::filesystem::path path_exe(wpath_exe);
  36. // Replace it with the current perl interpreter.
  37. result = boost::process::system((path_exe.parent_path() / "perl5.24.0.exe").string(), script, output_file);
  38. } else
  39. #else
  40. result = boost::process::system(script, output_file);
  41. #endif
  42. if (result < 0)
  43. BOOST_LOG_TRIVIAL(error) << "Script " << script << " on file " << path << " failed. Negative error code returned.";
  44. }
  45. }
  46. #endif
  47. } // namespace Slic3r