logging - Python: Write stdout to log file; output is hexadecimal not ascii -


i'm working on script call executable i/o files. i'm using subprocess , trying shell out exe , stdout log file. problem output simple ascii file , i'm getting hexadecimal file. learning program python (or language matter) so, i'm assuming there type of formatting can don't it. i've done fair bit of searching on site , others haven't i'm using subprocess for. "outradcorr" need on most...any ideas? more code on request.

import system modules

import os, sys, string, traceback, time, datetime import params subprocess import popen, pipe, stdout 

...some code here.....

write stdout log file

rad_log_file = open(dsfolder + '\\radcorr.log', 'w')  # loop through files in raw file list run radiometric correction rawfiles in rawfolderlist:      # define file base     rawbase = rawfiles.split(".")[0]     print ('\nprocessing file: %s \n')%( rawbase )      # define variables raw file process radcorr     radfile = rawfiles     pixfile = ('%s.pix')%( rawbase )     attfile = ('%s.att')%( rawbase )      # create windose bat file function     def rad_bat_writer( radcorr_bat ):         open(dsfolder + '\\radcorr.bat', 'a') rad_bat_file:             rad_bat_file.write(radcorr_bat + '\n')      # grab radcor input/output files , run radcorr.exe     radcorr = ('c:\\itres\\bin\\radcorr.exe -f 1 -j 100 -g 50 -s -1 -n -1 %s %s %s -i '+ rawfolder + '\%s,rb -o ' + radfolder + '\%s -a ' \     + radfolder + '\%s -c c:\\itres\\rad_cal_files\\%s -i 0 -v 0 -r y -r y -^^ 2') %( sum,scatter,shift,radfile,pixfile,attfile,rad_prefix )     # print out radcorr command     print radcorr     # execute radcorr , write stdout     outradcorr = popen("{};".format(radcorr), stdout=pipe, stderr=stdout)     line in outradcorr.stdout:         sys.stdout.write(line)         rad_log_file.write(line)      # write output log     rad_bat_writer( radcorr )  # close out exe , log files outradcorr.wait() rad_log_file.close() 

i using ultraedit view file, can view hex files in. not looking in hex mode. might confusing terminology here. file looks normal in notepad/notepad++/wordpad etc. ran script in debug mode, hit loop file file. first 2 files (1gb/file), output log looked fine. once radcorr.log file on 10kb, change normal ascii output binary file viewed looked hex. can't post images yet, google ultraedit hexadecimal.

still not sure why moved format. finally, output size 45kb. change view/edit hex mode in ultraedit , looks fine. wanted out there see if others had ideas why when specified log 'w' , not 'wb', instance.

i appreciate help. @j.f. sebastian i'll have test code posted, fix potential bugs down road.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -