this bash script can catch all the environment variables which are set when data is passed through STDIN eg such as:
echo "Hello" | ./script.sh
script.sh
#!/bin/bash
CAPTURE_FILE=/var/log/capture_data
env >> ${CAPTURE_FILE}
exit 1
it there any way i can do same in python??
RESOLVED:
this is the resultant python version..
#!/usr/bin/env python
import os
import sys
def capture():
log = os.environ
data = open("/tmp/capture.log", "a")
for key in log.keys():
data.write((key))
data.write(" : ")
for n in log[key]:
data.write('%s' % ((n)))
data.write("\n")
data.close()
sys.exit(1)
def main():
capture()
if __name__ == "__main__":
main()