bcarroll has asked for the
wisdom of the Perl Monks concerning the following question:

I had a crazy idea that I wanted to pass by the fellow monks, though not exactly specific to perl.

Is it possible to create an executable (compiled perl or other) that can trick the OS into thinking it is a text file? My thought is if such a thing can be done, this could be utilized to send logfile data to anything (remote database, parser, etc...).

Here is a use case: I have a bunch of servers that run various proprietary software applications that are only capable of writing logfiles locally, and I don't have access to these remote systems. If I can somehow replace the default logfile with this "magic", anything written to this file could be sent to my database, log collector server, etc...

Is this just a pipe dream?

Comment on Crazy question about writing to a text file that is actually an executable...

To slightly clarify what BrowserUk said, what you're looking for is already a feature of most operating systems, including pretty much any UNIX-based OS you like. The feature is usually referred to as "named pipes" or "FIFOs".

You use a command mkfifo to create what is basically a dummy entry in the filesystem. You then write your script to read lines from that filename in a loop. When there are no lines to be read, then Perl's readline operator (i.e. <$fh>) will automatically wait until lines are available.

Other processes can then just open that file in write mode and write lines to it, just like it was a normal file. Your script will wake up when lines are available and be able to process them. If your script is slow to process the data then the process writing the data will just act like it's writing to a slow disk. Nothing actually gets written to disk (except the directory entry for the filename); the data streams from the output filehandle of one process to the input handle of the other process.

This is basically just the same technique as chaining together commands in the shell using the pipe (|), but rather than the pipes being anonymous, they have filenames attached to them. Hence "named pipes".

Named pipes are pretty awesome for interprocess communication, though can be fiddly to set up, so generally people use things like TCP sockets instead. The one place where named pipes beat sockets is where (as in your question) either the reader or the writer has not been written with interprocess communication in mind, so you need to "trick" it into thinking it's reading from a plain old file.

I seem to remember at one point using named pipes to include a randomly generated message in my e-mail signatures, when at the time my mail client could only read signatures from a static text file.

trick the OS into thinking it is a text file
The OS would obey your orders! Just open your executable with a text editor. The OS can't, however, show you what you wish to see. It will only show what's in the executable depending on the configuration of the text editor and OS.

I have a bunch of servers that run various proprietary software applications that are only capable of writing logfiles locally, and I don't have access to these remote systems.

If you don't have access to these remote systems, then how could any possible information exchange happen?
So you must have some kind of remote access to these systems otherwise the question doesn't appear to make sense.Can you provide some more details?