www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Compile from stdin

reply Benjamin Schulte <aldoric gmx.de> writes:
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.
May 06 2008
next sibling parent Dawid Ci&#281;&#380;arkiewicz <dawid.ciezarkiewicz jabster.pl> writes:
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?
 
On Linux (and probably some other unixes) you can try: cat file.d | dmd /proc/self/fd/0
 Thanks in advance.
Hope this will works (haven't tried myself).
May 06 2008
prev sibling next sibling parent Kevin Bealer <kevinbealer gmail.com> writes:
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
May 06 2008
prev sibling parent reply BCS <ao pathlink.com> writes:
Reply to Benjamin,

 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.
 
linux only as well but their might be some way to force the <(...) construct to be usable Walter: any way we can get a "don't adjust the filename" flag?
May 06 2008
parent reply Walter Bright <newshound1 digitalmars.com> writes:
BCS wrote:
 Walter: any way we can get a "don't adjust the filename" flag?
I don't know what you mean.
May 08 2008
next sibling parent terranium <spam here.lot> writes:
Walter Bright Wrote:

 BCS wrote:
 Walter: any way we can get a "don't adjust the filename" flag?
I don't know what you mean.
maybe doing something like dmd CONIN -ofprog.exe
May 08 2008
prev sibling parent reply BCS <ao pathlink.com> writes:
Reply to Walter,

 BCS wrote:
 
 Walter: any way we can get a "don't adjust the filename" flag?
 
I don't know what you mean.
this: dmd foo looks for a file named "foo.d", I need to to look for "foo"
May 08 2008
parent reply Walter Bright <newshound1 digitalmars.com> writes:
BCS wrote:
 Reply to Walter,
 
 BCS wrote:

 Walter: any way we can get a "don't adjust the filename" flag?
I don't know what you mean.
this: dmd foo looks for a file named "foo.d", I need to to look for "foo"
Are you using linux or windows? Also, dmd looks at the file extension to see what to do with the file. .o means object file, .a means library, etc. Having no extension causes problems. Why not just put an extension on it?
May 08 2008
parent BCS <ao pathlink.com> writes:
Reply to Walter,

 BCS wrote:
 
 Reply to Walter,
 
 BCS wrote:
 
 Walter: any way we can get a "don't adjust the filename" flag?
 
I don't know what you mean.
this: dmd foo looks for a file named "foo.d", I need to to look for "foo"
Are you using linux or windows?
linux
 Also, dmd looks at the file extension
 to see what to do with the file. .o means object file, .a means
 library, etc. Having no extension causes problems. 
something like -iD / -iL / -iO flags would cover that. But I think that only source code would be used very often so making that the default would be reasonable in my book. using the unix convention of - refering to stdin would cover what the OP wanted: dmd -iD-
 Why not just put an extension on it?
 
Because I can't select the filename. I was trying to use the "<(command)" construct under bash. This replaces the given with a path to a named pipe that the given command's stdout can be accessed from. The name is not something I can effect.
May 08 2008