<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def run(cmd_str,cwd='.',verbose=False):
 """ an OS agnostic function to execute a command line Parameters cmd_str : str the str to execute with os.system() cwd : str the directory to execute the command in verbose : bool flag to echo to stdout complete cmd str Note ---- uses platform to detect OS and adds .exe suffix or ./ prefix as appropriate for Windows, if os.system returns non-zero, raises exception Example ------- """

    bwd = os.getcwd()
    os.chdir(cwd)
    try:
        exe_name = cmd_str.split()[0]
        if "window" in platform.platform().lower():
            if not exe_name.lower().endswith("exe"):
                raw = cmd_str.split()
                raw[0] = exe_name + ".exe"
                cmd_str = ' '.join(raw)
        else:
            if exe_name.lower().endswith('exe'):
                raw = cmd_str.split()
                exe_name = exe_name.replace('.exe','')
                raw[0] = exe_name
                cmd_str = '{0} {1} '.format(*raw)
            if os.path.exists(exe_name) and not exe_name.startswith('./'):
                cmd_str = "./" + cmd_str


    except Exception as e:
        os.chdir(bwd)
        raise Exception("run() error preprocessing command line :{0}".format(str(e)))
    if verbose:
        print("run():{0}".format(cmd_str))

    try:
        ret_val = os.system(cmd_str)
    except Exception as e:
        os.chdir(bwd)
        raise Exception("run() raised :{0}".format(str(e)))
    os.chdir(bwd)
    if "window" in platform.platform().lower():
        if ret_val != 0:
            raise Exception("run() returned non-zero")