Peter Duniho said:
Now, all _that_ said, for the specific example given, the OP has a very
specific need: to "know the details of the file redirection". In other
words, while his question asks about a specific solution to a problem, he
probably doesn't actually care about the exact solution, but rather simply
that his problem is solved.
Since while the process is running, there is in fact a standard input
stream, and it does in fact _have_ to be connected to the file in
question, my guess is that there _is_ some way to map the stream back to
the file.
...
In other words: dig around to look for some kind of API that, given the
Stream instance that corresponds to the standard input (i.e.
Console.OpenStandardInput()), see if there's a way to map that back to the
underlying OS object, and from there to the actual file involved.
It turns out there are two ways to do this in unmanaged code, one
documented, one undocumented, neither of them easy.
You can take get the operating system HANDLE by doing
_get_osfhandle( fileno( stdin ) )
The documented method of converting that to a file name is to use
CreateFileMapping
MapViewOfFile
GetMappedFileName
(That returns a device-relative name, as in
\Device\HarddiskVolume2\tmp\x.cpp)
GetLogicalDeviceStrings
QueryDosDevice
(This lets you convery to C:\tmp\x.cpp)
There's actually a knowledge base article describing this.
http://msdn.microsoft.com/en-us/library/aa366789.aspx
The undocumented method is a lot shorter, using NtQueryInformationFile.
However, this is all the wrong solution. The right solution is to design
the interface to the program so that you PROVIDE it the information it
needs. Hence, don't use redirection if you need the input file name.