piping input to an external script
tim.arnold at sas.com
Mon May 11 20:04:30 CEST 2009
Hi, I have some html files that I want to validate by using an external
script 'validate'. The html files need a doctype header attached before
validation. The files are in utf8 encoding. My code:
HEADER = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'
filename = 'mytest.html'
fd = codecs.open(filename,'rb',encoding='utf8')
s = HEADER + fd.read()
p = subprocess.Popen(['validate'],
validate = p.communicate(unicode(s,encoding='utf8'))
I get lots of lines like this:
Error at line 1, character 66:\tillegal character number 0
But I can give the command in a terminal 'cat mytest.html | validate' and
get reasonable output. My subprocess code must be wrong, but I could use
some help to see what the problem is.
More information about the Python-list