diff --git a/election_openstv.module b/election_openstv.module
index c871be0..ccb7422 100644
--- a/election_openstv.module
+++ b/election_openstv.module
@@ -429,9 +429,19 @@ function _election_openstv_get_command() {
 
 /**
  * Find out whether OpenSTV can be executed with the configured command.
+ *
+ * @param string $command
+ *   A shell command to run OpenSTV, which could be the full path to
+ *   runElection.py (if it is executable), another shell command such as
+ *   'openstv-run-election', or 'python FILENAME'.
+ *
+ * @return bool
+ *   FALSE if the command is definitely not executable, TRUE otherwise.
  */
 function _election_openstv_executable($command) {
-  $command_parts = explode(' ', $command);
+  // Split up the command by spaces, ignoring any spaces that are escaped by a
+  // backslash.
+  $command_parts = preg_split('/(?<!\\\) /', $command);
   $command_name = reset($command_parts);
   // Test whether the command name is an executable.
   if (!is_executable($command_name)) {
@@ -443,8 +453,8 @@ function _election_openstv_executable($command) {
   }
   // If the command format is something like "/usr/bin/python filename.py",
   // check whether the file exists and is readable.
-  if (strpos($command_name, 'python') !== FALSE) {
-    $filename = end($command_parts);
+  if (strpos($command_name, 'python') !== FALSE && count($command_parts) > 1) {
+    $filename = str_replace('\ ', ' ', end($command_parts));
     if (!is_readable($filename)) {
       return FALSE;
     }
