Python: Use subprocess to easily catch return values

Run system commands or call a sub-process and assign the return value to a variable. This makes it easy to pass the error up to your processes parent.
python-caught

#!/usr/bin/env python
import sys
import subprocess as p

retval = p.call('touch file', shell=True, stdin=p.PIPE, stdout=p.PIPE)
if retval != 0:
    exit(retval)
else:
    print("no fail")
Posted by admica   @   13 November 2009

Related Posts

Like this post? Share it!

Digg Twitter StumbleUpon Delicious Technorati Facebook RSS

0 Comments

No comments yet. Be the first to leave a comment !
Leave a Comment

Name

Email

Website

Previous Post
« Extend your router’s wifi range with a directional antenna
Next Post
System-config-firewall: GUI for configuring Fedora’s iptables »
Powered by Wordpress   |   Lunated designed by ZenVerse