Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #111 Launch other program

From current process, run program x with command-line parameters "a", "b".

import System.Process
spawnProcess x ["a","b"]
#include <stdlib.h>
int system("x a b");
using System.Diagnostics;
string[] args = { "a", "b"};
Process.Start(x, string.Join(" ", args));
import std.process;
spawnProcess([x, "a", "b"]);
program p
   integer :: i

   call execute_command_line("x a b", exitstat=i)
   print *, "Exit status of x was ", i

   call execute_command_line("x a b", wait=.false.)
   print *, "running x in the background"
end program p 
import "os/exec"
err := exec.Command("x", "a", "b").Run()
const { exec } = require('child_process');
exec(`${x} a b`);
Runtime.getRuntime().exec(new String[]{"x", "a", "b"});
(sb-ext:run-program '("a" "b") "/path/to/x")
os.execute(x .. 'a b')
exec($x . " a b");
uses process;
var
  p: tprocess;
begin
  p.Executable := 'program_x';
  p.Parameters.Add('a');
  p.Parameters.Add('b');
  p.Execute;
end.
system $x, 'a', 'b';
import subprocess
subprocess.call(['x', 'a', 'b'])
`x a b`
use std::process::Command;
let output = Command::new("x")
    .args(&["a", "b"])
    .spawn()
    .expect("failed to execute process");
use std::process::Command;
let output = Command::new("x")
        .args(&["a", "b"])
        .output()
        .expect("failed to execute process");
use std::process::Command;
let output = Command::new("x")
        .args(&["a", "b"])
        .status()
        .expect("failed to execute process");

New implementation...
< >
programming-idioms.org