Run external program and capture its output to stdout

There is RunThrough which captures the output and evaluates it. However, I would like the output as String. Is there a direct way without redirecting to temporary files etc.? Here is the code:

pdftohtml = "pdftohtml.exe";
pdf = "test.pdf";
ans = RunThrough[pdftohtml <> " -stdout " <> pdf, ""];


This fails with the error message

Syntax::sntx: Invalid syntax in or before
"<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">".


Is there a way to get to the output without evaluating it?

• Does StringJoin@ReadList["!"<>pdftohtml <> " -stdout " <> pdf, Character] work? – yohbs Apr 20 '17 at 14:10
• Or RunProcess[pdftohtml <> " -stdout " <> pdf, "StandardOutput"]? – yohbs Apr 20 '17 at 14:16
• Thanks I will try this tomorrow – Karsten W. Apr 20 '17 at 15:21
• RunProcess may need the list form (see docs) RunProcess[{pdftohtml,"-stdout",pdf},"StandardOutput"] – george2079 Apr 20 '17 at 20:08
• @yohbs: the first construct StringJoin... works perfectly. Please make that an answer, and I will gladly upvote & accept... – Karsten W. Apr 21 '17 at 12:49

StringJoin@ReadList["!"<>pdftohtml <> " -stdout " <> pdf, Character]

RunProcess[{pdftohtml," -stdout ",pdf}, "StandardOutput"]