arguments to be passed to program
associative array that represent environment variables to be passed to program pointed by path
Working directory for new process.
Parameters for process creation. See See std.process.Config
Max bytes of output to be captured
An std.typecons.Tuple!(int, "status", string, "output").
Example of running execute to run simple script
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.nullable); status4.status.should.be(0); status4.output.should.equal("hello world\n");
Example of running execute to run script that will print current working directory
import dshould; import std.conv: octal; const Path current_dir = Path.current; scope(exit) current_dir.chdir; 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\npwd;"); // Add permission to run this script root.join("test-script").setAttributes(octal!755); // Change current working directory to our root; root.chdir; // Do not pass current working directory // (script have to print current working directory) auto status0 = root.join("test-script").execute(["hello", "world"]); status0.status.should.be(0); status0.output.should.equal(root.toString ~ "\n"); // Create some other directory auto my_dir = root.join("my-dir"); my_dir.mkdir(); // Passs my-dir as workding directory for script auto status1 = root.join("test-script").execute( ["hello", "world"], null, my_dir.nullable); status1.status.should.be(0); status1.output.should.equal(my_dir.toString ~ "\n"); // Passs null path as workding direcotry for script auto status2 = root.join("test-script").execute( ["hello", "world"], null, Nullable!Path.init); status2.status.should.be(0); status2.output.should.equal(root.toString ~ "\n"); // Passs my-dir as workding directory for script (without nullable) auto status3 = root.join("test-script").execute( ["hello", "world"], null, my_dir); status3.status.should.be(0); status3.output.should.equal(my_dir.toString ~ "\n");
Execute the file pointed by path