DEV Community


Execute a Program in D

jessekphillips profile image Jesse Phillips Updated on ・1 min read


Another helpful tool is to be able to run another program as part of a script. This is one area I find D handles really well and allows for similar controls to shell pipes.

For this toolbox I'll stick with the basic.

import std.process;
import std.exception;

auto res = execute(["app name", "arg 1", "arg 2"]);
enforce(res.status == 0, "App exited with failure");

import std.stdio;
Enter fullscreen mode Exit fullscreen mode

This method will wait for processing to complete and provide all the std output. spawnProcess can be used to allow program execution while the app runs, remember to wait before your program exits.

I like this approach because it is not subject strange escaping and quote rules from the shell. Though there is escapeShellCommand to help you.

Discussion (0)

Editor guide