std.path.shell throws exception with garbage string
Andrej Mitrovic
andrej.mitrovich at gmail.com
Wed Mar 9 16:16:10 PST 2011
Found myself a solution. And probably the cause of the issue. shell()
doesn't expect a null-terminated string, but just a string with the
shell command without any newlines or nulls.
So I can do this (importing std.algorithm for until):
auto command = to!string(chBuffer[].until('\n'));
auto result = shell(command);
Not too shabby.
Still that error message wasn't of much help. shell() internally
creates a temp file with a random file name, temporarily redirects
stdout to that file to catch the contents of a system() invocation,
and then reads that file with readtext(). Somehow, something errors
out if there's a newline or null in the string, and it all explodes
with a weird error message.
More information about the Digitalmars-d-learn
mailing list