[Issue 17250] ProcessPipes (std.process) should provide a test for a null pid

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Mar 9 19:04:39 PST 2017


https://issues.dlang.org/show_bug.cgi?id=17250

Jon Degenhardt <jrdemail2000-dlang at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P2

--- Comment #1 from Jon Degenhardt <jrdemail2000-dlang at yahoo.com> ---
The ProcessPipes struct provides a method, pid(), that returns the Pid of the
attached process. The pid() method asserts if the private member is null:

    @property Pid pid() @safe nothrow
    {
        assert(_pid !is null);
        return _pid;
    }

The problem is that there is no method available to determine if pid is null
prior to call the pid() method.

In idiomatic use this unlikely to be an issue, as entering a block requiring
access to the pid is typically conditioned on successful creation of the pid.
An example from the doc:

    auto pipes = pipeProcess("my_application", Redirect.stdout |
Redirect.stderr);
    scope(exit) wait(pipes.pid);
    ... more code ...

In the above, the scope exit block is only entered if pid is successfully
created. However, if process creation is deferred, the pid might never be
assigned. E.g.

    ProcessPipes pipes;
    scope(exit) wait(pipes.pid);
    ... code ...
    pipes = pipeProcess("my_application", Redirect.stdout | Redirect.stderr);
    ... code ...

The above will fail in the 'wait(pipes.pid)' call if the _pid member is null.
What seems desired is a way to write something equivalent to:

    scope(exit) if (!pipes.isNullPid) wait(pipes.pid)

--


More information about the Digitalmars-d-bugs mailing list