///|
#borrow(argv, error)
extern "c" fn moonbit_g_subprocess_new(
  argv : FixedArray[Bytes],
  argv_len : Int,
  flags : Int,
  error : Ref[@glib.Nullable[@glib.Error_]],
) -> @glib.Nullable[Subprocess] = "moonbit_g_subprocess_new"

///|
/// Creates a new subprocess with the given argument vector and flags.
///
/// The first element of `argv` is the program to execute. The remaining
/// elements are passed as arguments.
pub fn Subprocess::new(
  argv : Array[String],
  flags : SubprocessFlags,
) -> Subprocess raise @glib.Error_ {
  let encoded = FixedArray::makei(argv.length(), fn(i) {
    @encoding/utf8.encode(argv[i])
  })
  let error_ : Ref[@glib.Nullable[@glib.Error_]] = Ref(@glib.Nullable::null())
  let result = moonbit_g_subprocess_new(
    encoded,
    argv.length(),
    flags.to_int(),
    error_,
  )
  match error_.val.to_option() {
    Some(e) => raise e
    None => ()
  }
  match result.to_option() {
    Some(proc) => proc
    None => abort("Subprocess::new returned null without error")
  }
}