Path.execute

Execute the file pointed by path * * Params: * args = arguments to be passed to program * env = associative array that represent environment variables * to be passed to program pointed by path * workDir = Working directory for new process. * config = Parameters for process creation. * See See std.process.Config * maxOutput = Max bytes of output to be captured * Returns: * An std.typecons.Tuple!(int, "status", string, "output").

  1. auto execute(string[] args, string[string] env, P workDir, std.process.Config config, size_t maxOutput)
    struct Path
    const
    execute
    (
    P = string
    )
    (
    in string[] args = []
    ,
    in string[string] env = null
    ,
    in P workDir = null
    ,
    in std.process.Config config = std.process.Config.none
    ,
    in size_t maxOutput = size_t.max
    )
    if (
    is(P == string)
    )
  2. auto execute(string[] args, string[string] env, P workDir, std.process.Config config, size_t maxOutput)

Examples

import dshould;
import std.conv: octal;
Path root = createTempPath();
scope(exit) root.remove();

// Create simple test script that will print its arguments
root.join("test-script").writeFile(
    "#!/usr/bin/env bash\necho \"$@\";");

// Add permission to run this script
root.join("test-script").setAttributes(octal!755);

// Run test script without args
auto status1 = root.join("test-script").execute;
status1.status.should.be(0);
status1.output.should.equal("\n");

auto status2 = root.join("test-script").execute(["hello", "world"]);
status2.status.should.be(0);
status2.output.should.equal("hello world\n");

auto status3 = root.join("test-script").execute(["hello", "world\nplus"]);
status3.status.should.be(0);
status3.output.should.equal("hello world\nplus\n");

auto status4 = root.join("test-script").execute(
        ["hello", "world"],
        null,
        root);
status4.status.should.be(0);
status4.output.should.equal("hello world\n");

Meta