[英]How to remove EOL escape characters in batch output
我有一个循环遍历.bat文件目录的Python脚本。 对于每个文件,它运行其批处理脚本,然后将输出与包含该文件输出的已保存文件进行比较,以测试.bat是否正确。 现在,我正在测试它,并将其作为测试文件:
@echo off
echo Good morning world and all who inhabit it! :D
然后,我有“解决方案”文件,如下所示:
Good morning world and all who inhabit it! :D
这是检查文件的代码:
for _, _, files in os.walk(dir):
for 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 is correct!\n" % (os.path.basename(f))
else:
print "\n%s gave incorrect output!\n" % (os.path.basename(f))
问题是,当.bat文件运行并产生其输出时,它在末尾添加了“ \\r\\n
”。 我也尝试通过将“ \\r\\n
”也放入解决方案文件中来解决该问题,但是在读取时将其更改为“ \\\\r\\\\n
”。 我怎样才能解决这个问题?
注意:显然,默认情况下,SO的代码格式突出显示“和”,回声中单词的存在根本不影响其功能。 只是不想让它混淆哈哈
您可以批量尝试:
@echo off
<nul set /p "=Good morning world and all who inhabit it! :D"
顺便说一句 我没有来自python的线索。
我对Windows的CoreUtils关于 tr
第二个建议是 :
@ECHO OFF &SETLOCAL
ECHO Good morning world and all who inhabit it! :D | tr -d \r
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.