Python Script Return Error Code
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads python script return value to shell with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack python exit code 2 Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign
Python Exception Exit Code
up Best way to return a value from a python script up vote 19 down vote favorite 12 I wrote a script in python that takes a few files, runs a few tests and counts the number of total_bugs while writing
Python Sys.exit Example
new files with information for each (bugs+more). To take a couple files from current working directory: myscript.py -i input_name1 input_name2 When that job is done, I'd like the script to 'return total_bugs' but I'm not sure on the best way to implement this. Currently, the script prints stuff like: [working directory] [files being opened] [completed work for file a + num_of_bugs_for_a] [completed work for file b + num_of_bugs_for_b] ... [work complete] A bit of help (notes/tips/code examples) could be helpful here. Btw, this needs python get exit code to work for windows and unix. python return return-value share|improve this question asked Aug 14 '13 at 12:11 ofer.sheffer 1,1542819 5 It's generally a bad idea to try to use the return value of an executable to return anything but an error code or 0 for success. What are you going to do with this value when it's returned? –geoffspear Aug 14 '13 at 12:13 1 Don't know about windows, but in linux it is common for programs to output the result to stdout. It seems like normally your script prints a bunch of information, but perhaps with a different flag (maybe c for count?), it just prints the total count of files, e.g. myscript.py -c -i input_name1 input_name2 –arghbleargh Aug 14 '13 at 12:18 @ Wooble, it is a script for finding bugs in report files. The value allows to estimate how well the report files are written. –ofer.sheffer Aug 14 '13 at 13:49 @arghbleargh, I decided to go with an extra bug report file but, pending on what my supervisor decides, I might change it to something like your suggestion. Thanks. –ofer.sheffer Aug 14 '13 at 13:51 add a comment| 1 Answer 1 active oldest votes up vote 43 down vote accepted If you want your script to return values, just do return [1,2,3] from a function wrapping your code but then you'd have to import your script from another script to even have any use for that information: R
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about
Python Exit With Error Message
Stack Overflow the company Business Learn more about hiring developers or posting ads with python exit code 255 us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a python check exit code community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Difference between exit(0) and exit(1) in Python up vote 52 down vote favorite 7 What's http://stackoverflow.com/questions/18231415/best-way-to-return-a-value-from-a-python-script the difference between exit(0) and exit(1) in Python? I tried looking around but didn't find a specific question on these lines. If it's already been answered, a link would be sufficient. python exit-code share|improve this question edited Sep 18 '15 at 18:43 Kasper Souren 4,29332661 asked Feb 24 '12 at 5:49 KodeSeeker 1,79784577 3 Here's a link to exit() in the docs, which took me forever to find. –Ryne http://stackoverflow.com/questions/9426045/difference-between-exit0-and-exit1-in-python Everett Apr 4 '14 at 2:08 1 keep in mind: The site module (which is imported automatically during startup, except if the -S command-line option is given) adds several constants to the built-in namespace. They are useful for the interactive interpreter shell and should not be used in programs, instead, use sys.exit() –Udi May 7 '14 at 18:12 add a comment| 5 Answers 5 active oldest votes up vote 91 down vote accepted 0 and 1 are the exit codes. exit(0) means a clean exit without any errors / problems exit(1) means there was some issue / error / problem and that is why the program is exiting. This is not Python specific and is pretty common. A non-zero exit code is treated as an abnormal exit, and at times, the error code indicates what the problem was. A zero error code means a successful exit. This is useful for other programs, shell, caller etc. to know what happened with your program and proceed accordingly. share|improve this answer answered Feb 24 '12 at 5:50 manojlds 154k26280306 2 And what about exit(-1) ? –Faizan Apr 1 '14 at 10:46 5 @Faizan: The exit code is an 8-bit value on Unix. If you invoke exit(-1), the value is equivalen
Ask a Question Need help? Post your question and get tips & solutions from a community of 418,626 IT Pros & Developers. It's quick & easy. Getting Python exit code when calling Python script from Java https://bytes.com/topic/python/answers/803518-getting-python-exit-code-when-calling-python-script-java-program program P: n/a Quill_Patricia I have a Python script which is used to load data into a database. Up to now this script has been run by customers from the Windows command prompt using "python edg_loader.pyc". Any error messages generated are written to a log file. A project team working in the same company as me here would like to use this loading utility. They write UI applications for Windows using Java. They were exit code able to launch the Python script from within Java by creating a Process using Java ProcessBuilder class. However, the way the error handling is currently implemented isn't really suitable for use in a UI application. As I'm sure you can appreciate it's not really feasible to tell users of a UI program to keep checking the log files while the loading is underway!!. Ideally they would like the Python loading utility to return an error python script return code and error message - the error message could then be displayed on a message box on the UI. I seem to be having problems implementing this. I tried using the sys.exit() method in my script and passed non -zero values. However the value wasn't picked up the by Java Process.exitValue() method - it kept picking up 0. On investigation it turned out that the exit value being read is from python.exe process, not from the Python script. Is there any way I can obtain the return value of a python script from a Java program? I did manage to get some sort of return error message. I wrote a test message to sys.stderr in the Python script and this was picked up by Java Process.getErrorSteam() method. However I would really like to get the return codes working if possible and would appreciate any suggestions on how to implement this. Thanks, Patricia Quill Jun 27 '08 #1 Post Reply Share this Question 4 Replies P: n/a Lie On Jun 18, 3:54*pm, Quill_Patri...@emc.com wrote: I have a Python script which is used to load data into a database. Up to now this script has been run by customers from the Windows command prompt using "python edg_loader.pyc". Any error messages generated are written to a log file. *A project team working in the same compan