import subprocess, os, os.path bat='f(o.bat' open(bat, 'w').write('echo foo\n') subprocess.check_call(os.path.join(os.getcwd(), bat))