1

I want to pipe the output of a program A in a program B. The program B doesn't support reading from stdin, only from files. Can I simply do A | B /dev/stdin ?

In fact it seems it works, but I want to make sure that when running the pipeline, the only things B gets from /dev/stdin are what A has written.

0

(See also JdeBP's comment)

Yes, but the recommended way is to use /dev/fd/0. It is mentioned e.g. in the book "Advanced Programming in the UNIX Environment":

It allows programs that use pathname arguments to handle standard input and standard output in the same manner as other pathnames.

/dev/fd/0 and /dev/stdin are the same device. See here for plenty of useful information:

| improve this answer | |
  • 2
    The question is phrased as a general case, and the general case answer is no. The program might be expecting the descriptor that it opens to the file to be seekable. Or writable. Or write lockable. Or it might be written to check the file with fstat() and abend if it finds anything other than a regular file. – JdeBP Jul 27 '17 at 21:20
  • @JdeBP Your arguments are correct, of course, but I did not understand the question the same way as you. See the second paragraph, isn't that what the OP means as "safe" in the title? Anyway, I have added a quote for clarification. – VPfB Jul 28 '17 at 5:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.