Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

External Process Execution

tango.sys.Process provides an easy to use, cross-platform class for executing external applications from within your program, and reading their output should you need. Let's jump right in. Here we have an example that lists the current directory through an external program.

private import;
private import tango.sys.Process;
private import tango.core.Exception;

 * Example program for the tango.sys.Process class.
void main()
    version (Windows)
        char[] command = "cmd.exe /c dir";
    else version (Posix)
        char[] command = "ls -l";
        assert(false, "Unsupported platform");

        auto p = new Process(command, null);
        Stdout.formatln ("Executing {}", p.toString);

        Stdout.formatln ("Output from process: {} (pid {})\n---", 

        Stdout.copy (p.stdout);
        Stdout ("---\n");

        auto result = p.wait();
        Stdout.formatln ("Process '{}' ({}) finished: {}",
                         p.programName,, result.toString);
    catch (ProcessException e)
        Stdout.formatln ("Process execution failed: {}", e.toString);