From 94465e975c865628736ec74364a31bab4b1dc030 Mon Sep 17 00:00:00 2001
From: Pierre Gergondet <pierre.gergondet@aist.go.jp>
Date: Wed, 5 Mar 2014 16:42:59 +0900
Subject: [PATCH] Improve run_command script handling

* Check for the existence of the script provided
* Pass an absolute path to the service
---
 scripts/run_command | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/scripts/run_command b/scripts/run_command
index bb3bf54..764e91c 100755
--- a/scripts/run_command
+++ b/scripts/run_command
@@ -70,6 +70,7 @@ class RosShell(InteractiveConsole):
 
 if __name__ == '__main__':
     import optparse
+    import os.path
     manifest = roslib.manifest.load_manifest('dynamic_graph_bridge')
     rospy.init_node('run_command', argv=sys.argv)
     sys.argv = rospy.myargv(argv=None)
@@ -82,12 +83,14 @@ if __name__ == '__main__':
 
     if args[:]:
         infile = args[0]
-        source = open(infile).read()
-        if not sh.client:
-            print("Connection to remote server has been lost.")
-            sys.exit(1)
-        response = sh.scriptClient(infile)
-        if not response:
-            print("Error while file parsing ")
+        if os.path.isfile(infile):
+            if not sh.client:
+                print("Connection to remote server has been lost.")
+                sys.exit(1)
+            response = sh.scriptClient(os.path.abspath(infile))
+            if not response:
+                print("Error while file parsing ")
+        else:
+            print("Provided file does not exist: %s"%(infile))
     else:
         sh.interact("Interacting with remote server.")
-- 
GitLab