Merge pull request #2085 from monarchdodra/processRet

Fix Issue 11308 - Don't use Voldemort types for std.process output
This commit is contained in:
Lars T. Kyllingstad 2014-04-18 12:48:55 +02:00
commit 9579b42cc5

View file

@ -1259,7 +1259,7 @@ A non-blocking version of $(LREF wait).
If the process associated with $(D pid) has already terminated, If the process associated with $(D pid) has already terminated,
$(D tryWait) has the exact same effect as $(D wait). $(D tryWait) has the exact same effect as $(D wait).
In this case, it returns a struct where the $(D terminated) field In this case, it returns a tuple where the $(D terminated) field
is set to $(D true) and the $(D status) field has the same is set to $(D true) and the $(D status) field has the same
interpretation as the return value of $(D wait). interpretation as the return value of $(D wait).
@ -1273,10 +1273,7 @@ get the exit code, but also to avoid the process becoming a "zombie"
when it finally terminates. (See $(LREF wait) for details). when it finally terminates. (See $(LREF wait) for details).
Returns: Returns:
A $(D struct) which contains the fields $(D bool terminated) An $(D std.typecons.Tuple!(bool, "terminated", int, "status")).
and $(D int status). (This will most likely change to become a
$(D std.typecons.Tuple!(bool,"terminated",int,"status")) in the future,
but a compiler bug currently prevents this.)
Throws: Throws:
$(LREF ProcessException) on failure. $(LREF ProcessException) on failure.
@ -1303,14 +1300,10 @@ by the time we reach the end of the scope.
*/ */
auto tryWait(Pid pid) @safe auto tryWait(Pid pid) @safe
{ {
struct TryWaitResult import std.typecons : Tuple;
{
bool terminated;
int status;
}
assert(pid !is null, "Called tryWait on a null Pid."); assert(pid !is null, "Called tryWait on a null Pid.");
auto code = pid.performWait(false); auto code = pid.performWait(false);
return TryWaitResult(pid._processID == Pid.terminated, code); return Tuple!(bool, "terminated", int, "status")(pid._processID == Pid.terminated, code);
} }
// unittest: This function is tested together with kill() below. // unittest: This function is tested together with kill() below.
@ -1946,10 +1939,7 @@ workDir = The working directory for the new process.
directory. directory.
Returns: Returns:
A $(D struct) which contains the fields $(D int status) and An $(D std.typecons.Tuple!(int, "status", string, "output")).
$(D string output). (This will most likely change to become a
$(D std.typecons.Tuple!(int,"status",string,"output")) in the future,
but a compiler bug currently prevents this.)
POSIX_specific: POSIX_specific:
If the process is terminated by a signal, the $(D status) field of If the process is terminated by a signal, the $(D status) field of
@ -2000,6 +1990,8 @@ private auto executeImpl(alias pipeFunc, Cmd)(
size_t maxOutput = size_t.max, size_t maxOutput = size_t.max,
in char[] workDir = null) in char[] workDir = null)
{ {
import std.typecons : Tuple;
auto p = pipeFunc(commandLine, Redirect.stdout | Redirect.stderrToStdout, auto p = pipeFunc(commandLine, Redirect.stdout | Redirect.stderrToStdout,
env, config, workDir); env, config, workDir);
@ -2022,8 +2014,7 @@ private auto executeImpl(alias pipeFunc, Cmd)(
// Exhaust the stream, if necessary. // Exhaust the stream, if necessary.
foreach (ubyte[] chunk; p.stdout.byChunk(defaultChunkSize)) { } foreach (ubyte[] chunk; p.stdout.byChunk(defaultChunkSize)) { }
struct ProcessOutput { int status; string output; } return Tuple!(int, "status", string, "output")(wait(p.pid), cast(string) a.data);
return ProcessOutput(wait(p.pid), cast(string) a.data);
} }
unittest unittest
@ -2059,6 +2050,19 @@ unittest
assert (r3.output.empty); assert (r3.output.empty);
} }
unittest
{
import std.typecons : Tuple;
void foo() //Just test the compilation
{
auto ret1 = execute(["dummy", "arg"]);
auto ret2 = executeShell("dummy arg");
static assert(is(typeof(ret1) == typeof(ret2)));
Tuple!(int, string) ret3 = execute(["dummy", "arg"]);
}
}
/// An exception that signals a problem with starting or waiting for a process. /// An exception that signals a problem with starting or waiting for a process.
class ProcessException : Exception class ProcessException : Exception