diff --git a/scripts/run_command b/scripts/run_command
index d1c8f1abd2260b8bd21b5e3101751f956825bda0..593b83ab9e713e920822f8423480c30699f051ec 100755
--- a/scripts/run_command
+++ b/scripts/run_command
@@ -67,12 +67,12 @@ class RosShell(InteractiveConsole):
                         return self.runcode(code, False)
                 response = self.client(str(source))
                 if response.standardoutput != "":
-                    print response.standardoutput[:-1]
+                    print(response.standardoutput[:-1])
                 if response.standarderror != "":
-                    print response.standarderror[:-1]
+                    print(response.standarderror[:-1])
                 elif response.result != "None":
-                    print response.result
-            except rospy.ServiceException, e:
+                    print(response.result)
+            except rospy.ServiceException as e:
                 print("Connection to remote server lost. Reconnecting...")
                 self.client = rospy.ServiceProxy(
                     'run_command', dynamic_graph_bridge_msgs.srv.RunCommand, True)
@@ -88,7 +88,11 @@ class RosShell(InteractiveConsole):
                 return self.runcode(c)
             else:
                 return True
-        except SyntaxError, OverflowError:
+        except SyntaxError:
+            self.showsyntaxerror()
+            self.cache = ""
+            return False
+        except OverflowError:
             self.showsyntaxerror()
             self.cache = ""
             return False