Skip to content

Instantly share code, notes, and snippets.

@adamrb
Created March 6, 2013 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamrb/5101545 to your computer and use it in GitHub Desktop.
Save adamrb/5101545 to your computer and use it in GitHub Desktop.
Looping over a shell script with python
#!/bin/bash
echo "Hello World: Line 1"
echo "Hello World: Line 2"
for i in $@; do
echo $i
done
#!/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