How to execute external program and process its output?

Marcin Kuszczak aarti at interia.pl
Mon Jul 31 14:22:55 PDT 2006


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.

BTW if D wants to be also language for scripting, it should have such a
possibility in standard library.

-- 
Regards
Marcin Kuszczak
(Aarti_pl)



More information about the Digitalmars-d-learn mailing list