Issue #8412: os.system() now accepts bytes, bytearray and str with
surrogates.
diff --git a/Misc/NEWS b/Misc/NEWS
index 7465609..18d7ca9 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -312,6 +312,9 @@
Library
-------
+- Issue #8412: os.system() now accepts bytes, bytearray and str with
+ surrogates.
+
- Issue #2987: RFC2732 support for urlparse (IPv6 addresses). Patch by Tony
Locke and Hans Ulrich Niedermann.
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index e6ef410..fb22eb6 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -2688,18 +2688,23 @@
wchar_t *command;
if (!PyArg_ParseTuple(args, "u:system", &command))
return NULL;
-#else
- char *command;
- if (!PyArg_ParseTuple(args, "s:system", &command))
- return NULL;
-#endif
+
Py_BEGIN_ALLOW_THREADS
-#ifdef MS_WINDOWS
sts = _wsystem(command);
-#else
- sts = system(command);
-#endif
Py_END_ALLOW_THREADS
+#else
+ PyObject *command_obj;
+ char *command;
+ if (!PyArg_ParseTuple(args, "O&:system",
+ PyUnicode_FSConverter, &command_obj))
+ return NULL;
+
+ command = bytes2str(command_obj, 1);
+ Py_BEGIN_ALLOW_THREADS
+ sts = system(command);
+ Py_END_ALLOW_THREADS
+ release_bytes(command_obj);
+#endif
return PyLong_FromLong(sts);
}
#endif