Getting the exit code of a subprocess
Hello, How can I find out the exit code of a process when using the subprocess module? I am passing an email message to a shell script and I need to know whether the shell script threw an error. Here is my code: p = Popen(cmd, stdout=None, stdin=PIPE, stderr=None) p.communicate(input=msg) I tried something like this: e_stat = p.communicate(input=msg) but the value of e_stat is always '(None, None)' -- Thanks & best regards, Jason Rissler -- https://mail.python.org/mailman/listinfo/python-list
ast.parse, ast.dump, but with comment preservation?
I wrote a little open-source tool to expose internal constructs in OpenAPI. Along the way, I added related functionality to: - Generate/update a function prototype to/from a class - JSON schema - Automatically add type annotations to all function arguments, class attributes, declarations, and assignments alongside a bunch of other features. All implemented using just the builtin modules (plus astor on Python < 3.9; and optionally black). Now I'm almost at the point where I can run it—without issue—against, e.g., the entire TensorFlow codebase. Unfortunately this is causing huge `diff`s because the comments aren't preserved (and there are some whitespace issues… but I should be able to resolve the latter). Is the only viable solution available to rewrite around redbaron | libcst? - I don't need to parse the comments just dump them out unedited whence they're found… Thanks for any suggestions PS: Library is https://github.com/SamuelMarks/cdd-python (might relicense with CC0… anyway too early for others to use; wait for the 0.1.0 release ;]) -- https://mail.python.org/mailman/listinfo/python-list
Re: Getting the exit code of a subprocess
On Wed, Dec 15 2021 at 09:38:48 PM, Jason wrote: > Hello, > > How can I find out the exit code of a process when using the > subprocess module? I am passing an email message to a shell script and > I need to know whether the shell script threw an error. > > Here is my code: > p = Popen(cmd, stdout=None, stdin=PIPE, stderr=None) > p.communicate(input=msg) > > I tried something like this: > e_stat = p.communicate(input=msg) > > but the value of e_stat is always '(None, None)' > You want to look at p.returncode after communicate returns: https://docs.python.org/3/library/subprocess.html#subprocess.Popen.returncode https://docs.python.org/3/library/subprocess.html#subprocess.Popen.communicate returns a tuple with the stdout and stderr contents. -- regards, kushal -- https://mail.python.org/mailman/listinfo/python-list
Re: Getting the exit code of a subprocess
On Wed, Dec 15, 2021 at 08:19:16PM -0800, Kushal Kumaran wrote: > On Wed, Dec 15 2021 at 09:38:48 PM, Jason wrote: > > Hello, > > > > How can I find out the exit code of a process when using the > > subprocess module? I am passing an email message to a shell script and > > I need to know whether the shell script threw an error. > > > > Here is my code: > > p = Popen(cmd, stdout=None, stdin=PIPE, stderr=None) > > p.communicate(input=msg) > > > > I tried something like this: > > e_stat = p.communicate(input=msg) > > > > but the value of e_stat is always '(None, None)' > > > > You want to look at p.returncode after communicate returns: > https://docs.python.org/3/library/subprocess.html#subprocess.Popen.returncode > > https://docs.python.org/3/library/subprocess.html#subprocess.Popen.communicate > returns a tuple with the stdout and stderr contents. Thank you, that is the info I needed! -- Jason Rissler -- https://mail.python.org/mailman/listinfo/python-list
Re: ast.parse, ast.dump, but with comment preservation?
On Thu, Dec 16, 2021 at 2:47 PM samue...@gmail.com wrote: > > I wrote a little open-source tool to expose internal constructs in OpenAPI. > Along the way, I added related functionality to: > - Generate/update a function prototype to/from a class > - JSON schema > - Automatically add type annotations to all function arguments, class > attributes, declarations, and assignments > > alongside a bunch of other features. All implemented using just the builtin > modules (plus astor on Python < 3.9; and optionally black). > > Now I'm almost at the point where I can run it—without issue—against, e.g., > the entire TensorFlow codebase. Unfortunately this is causing huge `diff`s > because the comments aren't preserved (and there are some whitespace issues… > but I should be able to resolve the latter). > > Is the only viable solution available to rewrite around redbaron | libcst? - > I don't need to parse the comments just dump them out unedited whence they're > found… > > Thanks for any suggestions > > PS: Library is https://github.com/SamuelMarks/cdd-python (might relicense > with CC0… anyway too early for others to use; wait for the 0.1.0 release ;]) I haven't actually used it, but what you may want to try is lib2to3. It's capable of full text reconstruction like you're trying to do. Otherwise: Every AST node contains line and column information, so you could possibly work the other way: keep the source code as well as the AST, and make changes line by line as you have need. ChrisA -- https://mail.python.org/mailman/listinfo/python-list