How to write the results of a batch file called in a Python script to a file -
i have python script in have directory of .bat files. loop through them , run each 1 through command line, save result of batch script file. far have this:
import subprocess _, _, files in os.walk(directory): f in files: fullpath = directory + os.path.basename(f) params = [fullpath] result = subprocess.list2cmdline(params)
however, sets result
variable path of .bat file, when need result of running code in ,bat file. have suggestions?
why calling list2cmdline
? doesn't call subprocess.
use subprocess.check_output
instead:
import os output = [] _, _, files in os.walk(directory): f in files: fullpath = os.path.join(directory, os.path.basename(f)) output.append(subprocess.check_output([fullpath])) print '\n'.join(output)
Comments
Post a Comment