July 30, 2007 Problem with std.process.execvp and redirected stdout. | ||||
---|---|---|---|---|
| ||||
The program I am invoking - slave.exe - simply displays its arguments on stdout. import std.process; import std.c.stdio; int main(string[] args) { // This compiles and runs. It creates out.txt but the file is // empty. string[] pargs = [ "?", "A", "B" ]; freopen("out.txt", "w", stdout); int rv = execvp("slave.exe", pargs); return rv; // If I build the following VC6 program it behaves as expected // I see the echoed arguments in out.txt /* char *pargs[4]; pargs[0] = "?"; pargs[1] = "A"; pargs[2] = "B"; pargs[3] = NULL; freopen("out.txt", "w", stdout); execvp("slave.exe", pargs); return 0; */ } Without the freopen, slave.exe displays the arguments to the console and then hangs - the C program behaves the same way in that case. I tried constructing an array of char* arguments explicitly with a terminating null, and then calling std.c.process.execvp, but the behavior is the same. |
July 30, 2007 Re: Problem with std.process.execvp and redirected stdout. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steve Teale | Steve Teale Wrote:
> The program I am invoking - slave.exe - simply displays its arguments on stdout.
>
> import std.process;
> import std.c.stdio;
>
> int main(string[] args)
> {
> // This compiles and runs. It creates out.txt but the file is
> // empty.
> string[] pargs = [ "?", "A", "B" ];
> freopen("out.txt", "w", stdout);
> int rv = execvp("slave.exe", pargs);
> return rv;
>
> // If I build the following VC6 program it behaves as expected
> // I see the echoed arguments in out.txt
> /*
> char *pargs[4];
> pargs[0] = "?";
> pargs[1] = "A";
> pargs[2] = "B";
> pargs[3] = NULL;
> freopen("out.txt", "w", stdout);
> execvp("slave.exe", pargs);
> return 0;
> */
> }
>
> Without the freopen, slave.exe displays the arguments to the console and then hangs - the C program behaves the same way in that case.
>
> I tried constructing an array of char* arguments explicitly with a terminating null, and then calling std.c.process.execvp, but the behavior is the same.
>
Sory about the double posting.
I eventually got what I wanted working with CreateFile and CreateProcess. I think the problem may be that the C library freopen function is not creating a Windows file handle that has its security descriptor set to inheritable. Before I did that in my implementation it was behaving the same way.
|
Copyright © 1999-2021 by the D Language Foundation