Craig Gidney
Craig Gidney

Reputation: 18296

Is there a way to cause a command line program requiring a file argument to use stdin?

I'm trying to get the command pdftotext to process data from stdin, instead of having to cache intermediate data in a temporary file. Note that the pdftotext command is being executed from a Java program.

pdftotext expects a file argument and, if one isn't given, prints usage information. stdin is ignored as far as I can tell.

I do have a non-portable solution (on linux use the pseudo-file '/dev/stdin'). An ideal solution would work on linux and windows, assuming the pdftotext program was present.

Upvotes: 3

Views: 259

Answers (1)

nos
nos

Reputation: 229214

pdftotext seems to support the convention of using - as a special way of saying 'stdin'. So running pdftotext - mypdf.txt will try to read the pdf document from stdin and output it to the mypdf.txt file. You can use - as the output file as well, in which case it'll output the converted pdf to stdout instead of a regular file.

Upvotes: 3

Related Questions