std.process.execute without capturing stderr?
berni
someone at somemail.de
Thu Sep 20 07:24:52 UTC 2018
I need to execute a program and capture stdout, which I hoped
std.process.execute would do. But unfortunatly this command also
captures stderr, which I need to be ignored. When looking at the
implementation of std.process.execute I see, that I can probably
do this by removing "Redirect.stderrToStdout" in the function
executeImpl. But for that I have to copy lots of functions from
phobos in my own code. Is there an easier way to do that?
In case you wonder why I need this: I'm currently using a PHP
frontend and a D backend. I'm calling the D routines with the PHP
exec command which works fine, but unfortunately removes trailing
whitespaces, that I need. Therefore I'd like to have a wrapper
that replaces all whitespace by some escape sequences which than
are restored in PHP. First I thought I can use sed for that, but
unfortunately the return code gets lost here. I'm using stderr to
show some progress information, which should be shown
immediately. (I've you've got other ideas how to get arround this
design flaw (as I see it) in php exec, I'd be happy too.)
I don't want to touch the D backend - that's not the place, where
the problem lies and when I decide to change the frontend I've to
remember to change the backend too, which I don't like.
Here my complete program:
> import std.process;
> import std.stdio;
> import std.array;
>
> int main(string[] args)
> {
> const result = execute(args[1..$]);
> writeln(result[1].replace("\\","\\\\").replace(" ","\\s"));
> return result[0];
> }
More information about the Digitalmars-d-learn
mailing list