with open(batch_filename, 'wt') as batchfile:
    batchfile.write(textwrap.dedent(
        """
        python hello.py
        if errorlevel 1 (
            @echo non-zero exit code: %errorlevel% - terminating
            exit
        )
        time /t
        date /t
    """
        ))
kwargs = dict(stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
    universal_newlines=True)
Run multiple programs sequentially in one Windows command prompt?