Skip to content
This repository

Quick fix for os.system requiring str parameter #1005

merged 3 commits into from over 2 years ago

3 participants

Jörgen Stenarson Thomas Kluyver Min RK
Jörgen Stenarson

This is work in progress that needs some feedback

os.system seems to require a str parameter, unicode is converted using ascii.

How should we handle this in a python3 compatible way? Should we extract system_raw to utils/

Thomas Kluyver

I expect Python 3 os.system will want unicode. If we know we're always starting with unicode, put it through py3compat.unicode_to_str (which encodes on Python 2 only). If the input can be either unicode or bytes on Python 2, use py3compat.cast_bytes_py2. There's a list of what's in py3compat here:

Jörgen Stenarson
Thomas Kluyver

Looks sensible to me - thanks, Jörgen. I guess there isn't a good way to test this, because it would rely on the existence of a particular network share.

I'll merge this soon, unless anyone objects or beats me to it.

Min RK

We should definitely add a unittest that just makes a simple !føø call, to protect from future failures to tackle unicode. The UNC share is a separate issue that is impossible to test, and we just have to be diligent (which I apparently failed to do, because while I did test on UNC shares, I do not have any non-ascii unicode shares).

Min RK

Also note that this bug affects all platforms, so both calls to os.system should be protected.

Jörgen Stenarson

I have also added the conversion to the non-windows code-path

Thomas Kluyver takluyver merged commit b206d90 into from November 17, 2011
Thomas Kluyver takluyver closed this November 17, 2011
Thomas Kluyver

Thanks. Merged, with a tiny fix for Python 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 3 unique commits by 1 author.

Nov 16, 2011
Quick fix for os.system requiring str parameter a44e04d
Use unicode_to_str from py3compat fb3b776
Nov 17, 2011
Add simple test for non-ascii characters in system_raw call. b206d90
This page is out of date. Refresh to see the latest.
2  IPython/core/
@@ -2082,8 +2082,10 @@ def system_raw(self, cmd):
2082 2082
             with AvoidUNCPath() as path:
2083 2083
                 if path is not None:
2084 2084
                     cmd = '"pushd %s &&"%s' % (path, cmd)
+                cmd = py3compat.unicode_to_str(cmd)
2085 2086
                 ec = os.system(cmd)
2086 2087
+            cmd = py3compat.unicode_to_str(cmd)
2087 2089
             ec = os.system(cmd)
2088 2090
2089 2091
         # We explicitly do NOT return the subprocess status code, because
8  IPython/core/tests/
@@ -220,3 +220,11 @@ def test_1(self):
220 220
         """Test safe_execfile with non-ascii path
221 221
222 222, {}, raise_exceptions=True)
+class TestSystemRaw(unittest.TestCase):
+    def test_1(self):
+        """Test system_raw with non-ascii cmd
+        """
+        cmd = ur'''python -c "u'åäö'"   '''

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.