system

system(string $command, int &$result_code = null): string|false

Executes an external command and streams its output straight to this process's stdout (returning the last line).

C C23

C23
#include <stdlib.h>

int main(void) {
    /* system(): run the shell, child stdout passes through, return the exit status */
    int code = system("echo hello system");
    return code; /* propagate the status (0 here) */
}
Output
hello system

C++ C++26

C++26
#include <cstdlib>

int main() {
    // std::system: run the shell, child stdout passes through, return the exit status
    int code = std::system("echo hello system");
    return code;
}
Output
hello system

C# v11.0.100

v11.0.100
using System.Diagnostics;

var psi = new ProcessStartInfo("echo"); // direct process, no shell
psi.ArgumentList.Add("hello");
psi.ArgumentList.Add("system");
using var p = Process.Start(psi)!; // stdout not redirected: inherits our console
p.WaitForExit();
Console.WriteLine($"exit={p.ExitCode}");
Output
hello system
exit=0

Go v1.27.4

v1.27.4
package main

import (
	"fmt"
	"os"
	"os/exec"
)

func main() {
	cmd := exec.Command("echo", "hello", "system")
	cmd.Stdout = os.Stdout // wire child stdout straight through
	if err := cmd.Run(); err != nil {
		panic(err)
	}
	fmt.Println("exit=0") // Run returns nil only for status 0
}
Output
hello system
exit=0

Java v27.0.1

v27.0.1
public class Main {
    public static void main(String[] args) throws Exception {
        // inheritIO: child stdout passes straight through to ours
        Process p = new ProcessBuilder("echo", "hello", "system").inheritIO().start();
        System.out.println("exit=" + p.waitFor());
    }
}
Output
hello system
exit=0

JavaScript v26.13.1

v26.13.1
const { spawnSync } = require("node:child_process");
// stdio "inherit": child output goes straight to our stdout, like system()
const r = spawnSync("echo", ["hello", "system"], { stdio: "inherit" });
console.log("exit=" + r.status);
Output
hello system
exit=0

PHP v8.6.0

v8.6.0
$last = system('echo hello system', $code); // child stdout streams to our stdout directly
echo "last=$last code=$code", PHP_EOL;       // return = last line; $code = exit status
Output
hello system
last=hello system code=0

Python v3.15.2

v3.15.2
import subprocess

# call(): stdout inherited (prints directly), returns the exit status
code = subprocess.call(["echo", "hello", "system"])
print(f"exit={code}")
Output
hello system
exit=0

Rust v1.99.1

v1.99.1
use std::process::Command;

fn main() {
    // .status(): child stdout passes through, returns the ExitStatus
    let status = Command::new("echo").arg("hello").arg("system").status().unwrap();
    println!("exit={}", status.code().unwrap());
}
Output
hello system
exit=0

TypeScript v26.13.1

v26.13.1
import { spawnSync } from "node:child_process";
// stdio "inherit": child output goes straight to our stdout, like system()
const r = spawnSync("echo", ["hello", "system"], { stdio: "inherit" });
console.log("exit=" + r.status);
Output
hello system
exit=0

Language differences

C: system() is the rawest wrapper — run via shell, pass output through, return the exit status (example); a signal interruption returns a non-zero value.

C++: std::system is C's system (example); the C++ standard library offers no finer control — pass-through/capture needs POSIX popen or a third-party library.

C#: without redirecting stdout the child inherits the console directly (the pass-through effect, example); ExitCode reads the exit status; the caller handles ordering (WaitForExit before reading ExitCode).

Go: wiring cmd.Stdout to os.Stdout is pass-through (example); Run() returning nil equals exit code 0, and a non-zero exit yields *ExitError.

Java: inheritIO() does pass-through in one call (example), wiring all three standard streams of the child to this process.

JavaScript: spawnSync with stdio: "inherit" is pass-through (example); status holds the exit code; for redirected capture see the exec/shell_exec entries.

PHP: system means execute while streaming every line straight to the output buffer, returning the last line (example); the only difference from exec is who holds the output.

Python: subprocess.call inherits stdout by default (pass-through, example) and returns the exit code; equivalent to run(...).returncode, while check_call raises on non-zero.

Rust: .status() passes through and returns an ExitStatus (example); .code() yields the exit code, None when killed by a signal.

TypeScript: same as JavaScript; for pass-through stdio: "inherit" is a one-liner — no manual piping needed.