#697: Encode expanded script on Python 2
diff --git a/tests/output_readers/test_rerun.py b/tests/output_readers/test_rerun.py
index 632606c6f..1d3a2c82c 100644
--- a/tests/output_readers/test_rerun.py
+++ b/tests/output_readers/test_rerun.py
@@ -30,6 +30,11 @@ def test_get_output_invalid_continuation_byte(self, popen_mock):
         actual = rerun.get_output('', '')
         assert actual == expected
 
+    @patch('thefuck.output_readers.rerun._wait_output')
+    def test_get_output_unicode_misspell(self, wait_output_mock):
+        rerun.get_output(u'pácman', u'pácman')
+        wait_output_mock.assert_called_once()
+
     def test_wait_output_is_slow(self, settings):
         assert rerun._wait_output(Mock(), True)
         self.proc_mock.wait.assert_called_once_with(settings.wait_slow_command)
diff --git a/thefuck/output_readers/read_log.py b/thefuck/output_readers/read_log.py
index 4da63e04a..0224a0dd3 100644
--- a/thefuck/output_readers/read_log.py
+++ b/thefuck/output_readers/read_log.py
@@ -40,6 +40,9 @@ def _group_by_calls(log):
 
 
 def _get_script_group_lines(grouped, script):
+    if six.PY2:
+        script = script.encode('utf-8')
+
     parts = shlex.split(script)
 
     for script_line, lines in reversed(grouped):
diff --git a/thefuck/output_readers/rerun.py b/thefuck/output_readers/rerun.py
index b50c0d3c5..b7ffe249d 100644
--- a/thefuck/output_readers/rerun.py
+++ b/thefuck/output_readers/rerun.py
@@ -1,5 +1,6 @@
 import os
 import shlex
+import six
 from subprocess import Popen, PIPE, STDOUT
 from psutil import AccessDenied, Process, TimeoutExpired
 from .. import logs
@@ -53,6 +54,9 @@ def get_output(script, expanded):
     env = dict(os.environ)
     env.update(settings.env)
 
+    if six.PY2:
+        expanded = expanded.encode('utf-8')
+
     split_expand = shlex.split(expanded)
     is_slow = split_expand[0] in settings.slow_commands if split_expand else False
     with logs.debug_time(u'Call: {}; with env: {}; is slow: {}'.format(

Fix #697