Last active
August 27, 2018 20:12
-
-
Save glwinsor/ced53ea01171c24243dc5c34e63425eb to your computer and use it in GitHub Desktop.
[system call and capture STDOUT]
This file contains 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
#! /usr/bin/python3 | |
from subprocess import Popen,PIPE,STDOUT | |
pmidString='' | |
command='/home/glwinsor/edirect/efetch -db pubmed -id 153904' | |
#captures STDOUT without having to use a redirect to a filename | |
#note that it captures bytes, not a string. Therefore need to specify universtal_newlines=True in order to retain newlines | |
p = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT,universal_newlines=True) | |
output = p.stdout.read() | |
# now write the contents of output to filename.txt | |
f = open('filename.txt', 'w') | |
f.write(str(output)) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment