Reputation: 918
I'm using convert and pango to create a png file from a string, where the string is C language code.
My conversion fails on many files but not all. It's difficult to track down the exact cause of the failure, but it would appear as if the string contains characters that are being interpreted by pango.
Is there a way to escape all tokens which can cause an error with Pango?
I'm calling convert like this via Python subprocess:
cmd = """convert pango:'<span foreground="black" background="white">"%s"</span>' outfile.png""" % C_string
TIA !
Upvotes: 1
Views: 397
Reputation: 24439
Use subprocess.PIPE
with subprocess.Popen.communicate
, and not waste time attempting to mix python, shell, and pango escape sequences. Pango should be escaped by glib, or cgi.
import glib
from subprocess import Popen, PIPE
cmd = 'convert pango:- outfile.png'
pid = Popen(cmd,
stdin=PIPE,
stdout=PIPE,
stderr=PIPE,
shell=True)
text_node = glib.markup_escape_text(C_string) # or cgi.escape(C_string)
pango = '<span foreground="black" background="white">{0}</span>'.format(text_node)
stdout, stderr = pid.communicate(pango)
Upvotes: 1