Compile from stdin

Kevin Bealer kevinbealer at gmail.com
Tue May 6 15:00:45 PDT 2008


Benjamin Schulte Wrote:

> Hi!
> Is there a way to compile a sourcecode from stdin? It would be very helpful to be able to compile a sourcecode from stdin direct into an object file, without saving it first into a temporary file.
> 
> Like using
> type test.d |dmd
> dmd < test.d
> 
> Or is it possible with gdc?
> 
> Thanks in advance.


The following works for me; it's a variation on what the other guy said but provides the ".d" ending.  Also a Linux-only solution.

ln -s /proc/self/fd/0 source.d
cat actual_source.d | dmd -ofresult source.d

Note that "source" can be used by multiple dmd processes to compile different files at the same time without conflict or synchronization, so you don't need to create per-process objects, but of course you might need to do something special if you want to compile multiple modules at once.

Kevin




More information about the Digitalmars-d mailing list