python - How to remove EOL escape characters in batch output -


i have python script loops through directory of .bat files. each file runs batch script , compares output saved file containing output of file should be, test if .bat correct. right i'm testing it, , have test file:

@echo off echo morning world , inhabit it! :d 

i have "solution" file this:

good morning world , inhabit it! :d 

this code check files:

for _, _, files in os.walk(dir):     f in files:         result = []         fpath = os.path.join(jobs, os.path.basename(f))         params = [fpath]         result.append(subprocess.check_output([params]))          expectedname = dir2 + os.path.basename(f) + ".test"         expectedfile = open(expectedname, 'r')         expected = []         expected.append(expectedfile.read())         print '\nexpected: %s\nactual:   %s' % (expected, result)          if result == expected:             print "\n%s correct!\n" % (os.path.basename(f))         else:             print "\n%s gave incorrect output!\n" % (os.path.basename(f)) 

the problem is, when .bat file runs , produces output, has "\r\n" added onto end. tried working around putting "\r\n" in solution file too, changes "\\r\\n" when read. how can fix this?

note: apparently so's code formatting highlights "and" default, presence of word in echo doesn't affect it's functionality @ all. didn't want confusing haha

you can try in batch:

@echo off <nul set /p "=good morning world , inhabit it! :d" 

btw. have no clue python.


and second suggestion tr coreutils windows:

@echo off &setlocal echo morning world , inhabit it! :d | tr -d \r 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -