Created
March 6, 2013 18:05
-
-
Save adamrb/5101545 to your computer and use it in GitHub Desktop.
Looping over a shell script with python
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
#!/bin/bash | |
echo "Hello World: Line 1" | |
echo "Hello World: Line 2" | |
for i in $@; do | |
echo $i | |
done |
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/env python | |
def readscript(script, *args): | |
import subprocess | |
command=list(args) | |
command.insert(0,script) | |
proc = subprocess.Popen(command,stdout=subprocess.PIPE) | |
output = [] | |
for line in iter(proc.stdout.readline,''): | |
output.append(line.rstrip()) | |
return output | |
commandoutput = readscript("./hello_world.sh", "arg1", "arg2", "arg3") | |
print commandoutput |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment