/TeXmacs-1.0.7.11-src/src/Plugins/Unix/unix_sys_utils.cpp

# · C++ · 36 lines · 22 code · 5 blank · 9 comment · 1 complexity · 7bf8a51b9d3a8259d7a97adbde3b93a0 MD5 · raw file

  1. /******************************************************************************
  2. * MODULE : unix_sys_utils.cpp
  3. * DESCRIPTION: external command handling
  4. * COPYRIGHT : (C) 2009 David MICHEL
  5. *******************************************************************************
  6. * This software falls under the GNU general public license version 3 or later.
  7. * It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
  8. * in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
  9. ******************************************************************************/
  10. #include "unix_sys_utils.hpp"
  11. #include "file.hpp"
  12. #include <stdlib.h>
  13. int
  14. unix_system (string s) {
  15. char* _s = as_charp (s * " > /dev/null 2>&1");
  16. int ret = system (_s);
  17. tm_delete_array (_s);
  18. return ret;
  19. }
  20. int
  21. unix_system (string cmd, string& result) {
  22. url temp= url_temp ();
  23. string temp_s= escape_sh (concretize (temp));
  24. char* _cmd = as_charp (cmd * " > " * temp_s * " 2>&1");
  25. int ret = system (_cmd);
  26. tm_delete_array (_cmd);
  27. bool flag= load_string (temp, result, false);
  28. remove (temp);
  29. if (flag) result= "";
  30. return ret;
  31. }