Last active
December 27, 2015 09:49
-
-
Save samuell/7306958 to your computer and use it in GitHub Desktop.
A convenience method for executing external commands and getting the output, in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import subprocess as sub | |
| def exec_cmd(commandstr): | |
| proc = sub.Popen(commandstr, stdout=sub.PIPE, shell=True) | |
| return proc.communicate()[0].strip() |
Author
Author
Learned, in this thread [1], that I can do:
import subprocess as sub
output = sub.check_output("java -jar SomeJarFile.jar")... or (if using http://amoffat.github.io/sh/):
import sh
output = sh.java("-jar", "SomeJarFile.jar")Nice!
[1] https://plus.google.com/u/0/106548631604770110294/posts/Z87xvsNcGWY
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Used like this, for executing jar files: