How to execute external program and process its output?

Tom S h3r3tic at remove.mat.uni.torun.pl
Mon Jul 31 15:25:49 PDT 2006


Marcin Kuszczak wrote:
> Pragma wrote:
> 
>> char[] commandline = "echo 'hello world' > output.txt";
>> std.process.system(commandline);
>> writefln("result: %s",std.file.read("output.txt"));
> 
> I had to modify a little bit program, but then it works - thanks a lot!
> 
> --
> void main() {
>   char[] commandline = "svn info >output.txt 2>&1";
>   std.process.system(commandline);
>   char[] result = cast(char[])(std.file.read("output.txt"));  
>   writefln("result: %s", result);
> }
> --
> 
> In the meantime I found also that there should be functions on C API
> 
> --
> #include <stdio.h>
> FILE *popen( const char *command, const char *type);
> int pclose( FILE *stream);
> --
> 
> but as I see it is not wrapped by D. I don't have any idea how to do it. If
> anyone can give some more info it would be great.

extern (C) {
     typedef void FILE;
     FILE* popen(char* cmd, char* type);
     int pclose(FILE* stream);
}

should work



More information about the Digitalmars-d-learn mailing list