Calling external programs from D

BCS BCS_member at pathlink.com
Tue Apr 11 09:37:01 PDT 2006


In article <e1g3sr$212p$1 at digitaldaemon.com>, Lionello Lunesu says...
>
>Just some idea:
>
>Wouldn't it be nice if there were an "extern (System)" calling 
>convention that would start external programs?
>
>For example:
>
>#extern (System) int wget(...);
>#
>#int main() {
>#  return wget("http://whatever");
>#}
>
>This would boost productivity especially for D scripts. Only too often I 
>need a small, temporary program to process some data and I wish I had 
>the compilable source of wget/grep/utility-x at hand to incorporate 
>their functionality.
>
>Seems easy enough to implement using spawning/waiting. The program can 
>be declared with "..." or some defined arugments, but all arguments to 
>the function would have to be cast to char[] for passing to the new 
>process. Would of course be even cooler if the linker could pull in the 
>external program's main(), but I suppose that's a bit tricky :)
>
>L.



As for accessing stdin/stdout, let them return a Stream type spliced in with
some pipes. You'd have to ditch the wait though.

extern (System) Stream sed(...);

int main()
{
auto io sed("s/hello/word");
io.writeLine(“hello to all you out there”);
wrietf(io.readLine());
// prints “word to all you out there”
return 0;
}

I’m not sure how to get the return value.







More information about the Digitalmars-d mailing list