1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! A library which provides an interface for [ConPTY].
//!
//! ```ignore
//! use std::io::prelude::*;
//!
//! let mut proc = conpty::spawn("echo Hello World").unwrap();
//! let mut reader = proc.output().unwrap();
//!
//! let mut buf = [0; 1028];
//! let n = reader.read(&mut buf).unwrap();
//!
//! assert!(String::from_utf8_lossy(&buf).contains("Hello World"));
//! ```
//!
//! [ConPTY]: https://devblogs.microsoft.com/commandline/windows-command-line-introducing-the-windows-pseudo-console-conpty/

#![warn(
    missing_docs,
    future_incompatible,
    single_use_lifetimes,
    trivial_casts,
    trivial_numeric_casts,
    unreachable_pub,
    unused_extern_crates,
    unused_import_braces,
    unused_qualifications,
    unused_results,
    unused_variables,
    variant_size_differences,
    missing_debug_implementations,
    rust_2018_idioms
)]

use std::{
    ffi::{OsStr, OsString},
    process::Command,
};

use error::Error;

pub mod console;
pub mod error;
pub mod io;

mod process;
mod util;

pub use process::Process;

/// Spawns a command using `cmd.exe`.
pub fn spawn(command: impl AsRef<OsStr>) -> Result<Process, Error> {
    let mut cmd = OsString::new();
    cmd.push("cmd /C ");
    cmd.push(command);

    Process::spawn(Command::new(&cmd))
}