From 4812fac33e25f0b384d473b597e93508725ce058 Mon Sep 17 00:00:00 2001 From: "zdenop@gmail.com" Date: Sun, 23 Dec 2012 17:52:42 +0000 Subject: [PATCH] Fix issue 427: print result to stdout instead to file git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@813 d0cd1f9f-072b-0410-8dd7-cf729c803f20 --- api/tesseractmain.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/api/tesseractmain.cpp b/api/tesseractmain.cpp index aca6b880..4e213b11 100644 --- a/api/tesseractmain.cpp +++ b/api/tesseractmain.cpp @@ -100,7 +100,7 @@ int main(int argc, char **argv) { } if (output == NULL && noocr == false) { - fprintf(stderr, _("Usage:%s imagename outputbase [-l lang] " + fprintf(stderr, _("Usage:%s imagename outputbase|stdout [-l lang] " "[-psm pagesegmode] [configfile...]\n\n"), argv[0]); fprintf(stderr, _("pagesegmode values are:\n" @@ -186,12 +186,16 @@ int main(int argc, char **argv) { api.GetBoolVariable("tessedit_create_hocr", &output_hocr); bool output_box = false; api.GetBoolVariable("tessedit_create_boxfile", &output_box); - STRING outfile = output; - outfile += output_hocr ? ".html" : output_box ? ".box" : ".txt"; - FILE* fout = fopen(outfile.string(), "wb"); - if (fout == NULL) { - fprintf(stderr, _("Cannot create output file %s\n"), outfile.string()); - exit(1); + + FILE* fout = stdout; + if (strcmp(output, "-") && strcmp(output, "stdout")) { + STRING outfile = output; + outfile += output_hocr ? ".html" : output_box ? ".box" : ".txt"; + fout = fopen(outfile.string(), "wb"); + if (fout == NULL) { + fprintf(stderr, _("Cannot create output file %s\n"), outfile.string()); + exit(1); + } } STRING text_out; @@ -200,7 +204,10 @@ int main(int argc, char **argv) { } fwrite(text_out.string(), 1, text_out.length(), fout); - fclose(fout); + if (fout != stdout) + fclose(fout); + else + clearerr(fout); return 0; // Normal exit }