How to execute external program and process its output?
Marcin Kuszczak
aarti at interia.pl
Mon Jul 31 16:19:09 PDT 2006
Tom S wrote:
> 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
Thanks! using C was easier than I thought...
(Second method still does not work for me, but it is just a mater of
time :-) )
--
Regards
Marcin Kuszczak
(Aarti_pl)
More information about the Digitalmars-d-learn
mailing list