changeset 29141:f873857f5f86

system: Support executing commands with non-ASCII characters on Windows (bug #59572). * liboctave/system/lo-sysdep.h, liboctave/system/lo-sysdep.cc (octave::sys::system): Add new function. * libinterp/corefcn/toplev.cc (Fsystem), libinterp/corefcn/oct-hist.cc (history_system::do_edit_history): Use new function. * src/mkoctfile.in.cc (run_command): Add FIXME note.
author Markus Mützel <markus.muetzel@gmx.de>
date Sun, 29 Nov 2020 14:20:08 +0100
parents c7498b5aece0
children 1024bc946c95
files libinterp/corefcn/oct-hist.cc libinterp/corefcn/toplev.cc liboctave/system/lo-sysdep.cc liboctave/system/lo-sysdep.h src/mkoctfile.in.cc
diffstat 5 files changed, 19 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/oct-hist.cc	Fri Dec 04 18:33:23 2020 +0100
+++ b/libinterp/corefcn/oct-hist.cc	Sun Nov 29 14:20:08 2020 +0100
@@ -469,7 +469,7 @@
     volatile interrupt_handler old_interrupt_handler
       = ignore_interrupts ();
 
-    int status = system (cmd.c_str ());
+    int status = octave::sys::system (cmd);
 
     set_interrupt_handler (old_interrupt_handler);
 
--- a/libinterp/corefcn/toplev.cc	Fri Dec 04 18:33:23 2020 +0100
+++ b/libinterp/corefcn/toplev.cc	Sun Nov 29 14:20:08 2020 +0100
@@ -293,7 +293,7 @@
     retval = run_command_and_return_output (cmd_str);
   else
     {
-      int status = system (cmd_str.c_str ());
+      int status = octave::sys::system (cmd_str);
 
       // The value in status is as returned by waitpid.  If
       // the process exited normally, extract the actual exit
--- a/liboctave/system/lo-sysdep.cc	Fri Dec 04 18:33:23 2020 +0100
+++ b/liboctave/system/lo-sysdep.cc	Sun Nov 29 14:20:08 2020 +0100
@@ -27,6 +27,8 @@
 #  include "config.h"
 #endif
 
+#include <cstdlib>
+
 #include "dir-ops.h"
 #include "file-ops.h"
 #include "lo-error.h"
@@ -51,6 +53,18 @@
 {
   namespace sys
   {
+    int
+    system (const std::string& cmd_str)
+    {
+#if defined (OCTAVE_USE_WINDOWS_API)
+      const std::wstring wcmd_str =  u8_to_wstring (cmd_str);
+
+      return _wsystem (wcmd_str.c_str ());
+#else
+      return ::system (cmd_str.c_str ());
+#endif
+    }
+
     std::string
     getcwd (void)
     {
--- a/liboctave/system/lo-sysdep.h	Fri Dec 04 18:33:23 2020 +0100
+++ b/liboctave/system/lo-sysdep.h	Sun Nov 29 14:20:08 2020 +0100
@@ -41,6 +41,8 @@
 {
   namespace sys
   {
+    extern int system (const std::string& cmd_str);
+
     extern std::string getcwd (void);
 
     extern int chdir (const std::string&);
--- a/src/mkoctfile.in.cc	Fri Dec 04 18:33:23 2020 +0100
+++ b/src/mkoctfile.in.cc	Sun Nov 29 14:20:08 2020 +0100
@@ -589,6 +589,7 @@
   if (verbose)
     std::cout << cmd << std::endl;
 
+  // FIXME: Call _wsystem on Windows or octave::sys::system.
   int result = system (cmd.c_str ());
 
   if (octave_wifexited_wrapper (result))