# Execute a program from zig

**URL:** <https://ziggit.dev/t/execute-a-program-from-zig/5819>\
**Category:** Help\
**Tags:** standard-library\
**Created:** [August 30, 2024, 8:06pm UTC](https://ziggit.dev/t/execute-a-program-from-zig/5819 "2024-08-30T20:06:33Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![dimdin](https://ziggit.dev/user_avatar/ziggit.dev/dimdin/32/1457_2.png) [@dimdin](https://ziggit.dev/u/dimdin)\
**Post date:** [August 30, 2024, 8:25pm UTC](https://ziggit.dev/t/execute-a-program-from-zig/5819/2 "2024-08-30T20:25:29Z")

</div>

Functions from `std.os` moved to `std.posix`.

Probably what you want is not the unix specific `exec` that replaces the current process, but the `spawn`, `spawnAndWait`, or `run` function of [std.process.Child](https://ziglang.org/documentation/master/std/#std.process.Child)

Test Example:  
_test.zig_

```zig
const std = @import("std");

test {
    const argv = [_][]const u8{ "echo", "Hello", "World" };
    var child = std.process.Child.init(&argv, std.testing.allocator);
    try child.spawn();
    const exit_code = child.wait();
    try std.testing.expectEqual(exit_code, std.process.Child.Term{ .Exited = 0 });
}

```

Run as:

```shell
> zig test test.zig
Hello World
All 1 tests passed.

```

---

_[View the full topic](https://ziggit.dev/t/execute-a-program-from-zig/5819)._
