SLIDER-153 python script working: stdout and stderr is being printed after the end of the process
Project: http://git-wip-us.apache.org/repos/asf/incubator-slider/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-slider/commit/06816c4c Tree: http://git-wip-us.apache.org/repos/asf/incubator-slider/tree/06816c4c Diff: http://git-wip-us.apache.org/repos/asf/incubator-slider/diff/06816c4c Branch: refs/heads/feature/SLIDER-151_Implement_full_slider_API_in_REST_and_switch_client_to_it Commit: 06816c4cd6ffbb94014ff95250f26c5028723a09 Parents: acdfe5b Author: Steve Loughran <ste...@apache.org> Authored: Tue Jun 24 10:52:10 2014 -0700 Committer: Steve Loughran <ste...@apache.org> Committed: Tue Jun 24 10:52:10 2014 -0700 ---------------------------------------------------------------------- slider-assembly/src/main/scripts/slider.py | 28 ++++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-slider/blob/06816c4c/slider-assembly/src/main/scripts/slider.py ---------------------------------------------------------------------- diff --git a/slider-assembly/src/main/scripts/slider.py b/slider-assembly/src/main/scripts/slider.py index 2c1f4b3..cfad59a 100644 --- a/slider-assembly/src/main/scripts/slider.py +++ b/slider-assembly/src/main/scripts/slider.py @@ -97,21 +97,27 @@ def main(): print "slider_home = \"%s\"" % slider_home print "slider_jvm_opts = \"%s\"" % slider_jvm_opts print "slider_classpath = \"%s\"" % slider_classpath - - - commandline = ["java",] + + #java = "/usr/bin/java" + java = "java" + commandline = [java, + "-classpath", + slider_classpath, + SLIDER_CLASSNAME] # commandline.append(slider_jvm_opts) - commandline.append("-classpath") - commandline.append(slider_classpath) - commandline.append(SLIDER_CLASSNAME) commandline.extend(args) print "ready to exec : %s" % commandline # docs warn of using PIPE on stderr - return subprocess.call(commandline, - stdin=None, + exe = subprocess.Popen(commandline, + stdin=subprocess.PIPE, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, + stderr=subprocess.PIPE, shell=False) + exe.wait() + out, err = exe.communicate() + print "stdout : ", out.decode() + print "stderr : ", err.decode() + return exe.returncode @@ -122,7 +128,9 @@ if __name__ == '__main__': try: rv = main() if rv != 0: - print "exit code = %d" % rv + print "Failed with exit code = %d" % rv + else: + print "Success" except Exception as e: print "Exception: %s " % e.message rv = -1