#!/usr/bin/env python

import os
import string
import sys

class SpawnError(Exception):   # the exception we throw if any error occurs
    def __init__(self, value): # constructorcommand
        self.value = value
    def __str__(self):         # string representation
        return `self.value`


def run_command(args):
    """ run a command in the local directory """
    name = args[0]; 
    if (name== None): return
    rc = os.fork();
    if (rc == 0):
        rc = os.execvp(name, args)
    else:
        os.waitpid(rc, 0)

if __name__ == "__main__":
    f = open("/dev/sct_log", "r");
    args = ["sct_logctrl", "-f", str(f.fileno())];
    args = args + sys.argv[1:] + ["flush"];
    run_command(args);
    args = ["sct_logctrl", "enable"];
    run_command(args); 
    while 1:
        sys.stdout.write(f.readline())
    
