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
This commit is contained in:
zdenop@gmail.com 2012-12-23 17:52:42 +00:00
parent 8a2b5f0ead
commit 4812fac33e

View File

@ -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,13 +186,17 @@ int main(int argc, char **argv) {
api.GetBoolVariable("tessedit_create_hocr", &output_hocr);
bool output_box = false;
api.GetBoolVariable("tessedit_create_boxfile", &output_box);
FILE* fout = stdout;
if (strcmp(output, "-") && strcmp(output, "stdout")) {
STRING outfile = output;
outfile += output_hocr ? ".html" : output_box ? ".box" : ".txt";
FILE* fout = fopen(outfile.string(), "wb");
fout = fopen(outfile.string(), "wb");
if (fout == NULL) {
fprintf(stderr, _("Cannot create output file %s\n"), outfile.string());
exit(1);
}
}
STRING text_out;
if (!api.ProcessPages(image, NULL, 0, &text_out)) {
@ -200,7 +204,10 @@ int main(int argc, char **argv) {
}
fwrite(text_out.string(), 1, text_out.length(), fout);
if (fout != stdout)
fclose(fout);
else
clearerr(fout);
return 0; // Normal exit
}