How to execute external program and process its output?

Pragma ericanderton at yahoo.com
Mon Jul 31 13:40:35 PDT 2006


Marcin Kuszczak wrote:
> Hello!
> 
> I am trying to execute external command from D program, and then process its
> output. spawnvp() doesn't seem to be enough as it does not return output,
> but just status as int.
> 
> How to achieve it in D (I don't know method also in C(++), so even this will
> help <g>)?
> 
> ---
> Regards
> Marcin Kuszczak
> (Aarti_pl)

Marcin,
   I don't know the "correct" way to do this, but perhaps I can offer a 
short-term hack to get you by?


char[] commandline = "echo 'hello world' > output.txt";
std.process.system(commandline);
writefln("result: %s",std.file.read("output.txt"));


Sure its not pretty, but it does work.



More information about the Digitalmars-d-learn mailing list