A file URI scheme makes it possible to specify an URI to a file stored locally, such as file:///home/demo/sample.

Could it be used to specify stdin?

For instance, with CURL:

curl file:///home/demo/sample

shows the contents of the file;

echo "Hello" | curl file:///dev/fd/0

gives an empty result, while I would expect it to show “Hello”. By the way:

echo "Hello" | cat /dev/fd/0

actually displays “Hello” to the output.

What should I put after file:// to target stdin?

Context: I'm experimenting with Motion which is able to read data from an HTTP URI or a file specified as file://, but doesn't seem to have an option to read a video stream directly from stdin (and a related question asked nearly two years ago was never answered). I want to be able to trick the app to think that it reads a file, when it actually is reading the output from ffmpeg.

  • 1
    This is likely to be fairly application-dependent. I'd guess curl doesn't like reading a device file for its file:// URLs, hence no easy file:///dev/stdin or similar. You might have better luck creating a FIFO and reading from that, or just using temp files. – Tom Hunt Nov 11 '15 at 23:19
curl file:///dev/fd/0

IS the correct way to make curl read from file descriptor 0 (stdin).

Take any readable textfile, do

<theTextFile.txt curl file:///dev/fd/0

And it should work just like cat.

Your problem is "How do I make curl read from a pipe?" and I'm afraid the answer is: patch curl's source code.

If you analyze the strace of curl on the example up top, you'll see it mmaps the file. mmaping won't work if the file is a pipe. If curl used regular read and write system calls, there wouldn't be any difference between <theTextFile.txt curl file:///dev/fd/0 and cat theTextFile.txt curl | file:///dev/fd/0, which is how it should be, IMO.

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.