CreateProcessW
This crate provides an API similar to std::process
to create
and handle processes on Windows using the Win32 API through the
windows-rs crate (see this example).
Its main difference with std::process::Command
is that it allows running
a command string instead of having to pass the command executable and the
arguments separately.
This is equivalent of running:
.arg
.arg
.spawn.expect;
new
The only difference will be that the Child
instance will use the PID of
the command instead of the PID of cmd.exe
. This is important because
calling .kill()
in the code above does not work as it kills the PID
of cmd.exe
instead of the actual command that has been ran.
Usage
Add the following to your Cargo.toml
:
[]
= "0.1.0"
This crate doesn't follow Rust's naming recommendations. If you want to stay consistent with other imported crates, use the following:
[]
= { = "0.1.0", = "CreateProcessW" }
Create a command
The Command
struct is used to configure and spawn processes:
use Command;
let command = new
.inherit_handles
.current_dir;
Spawning a process
The spawn
function spawns the process and returns a
Child
that represents the spawned child process.
use Command;
let child = new
.spawn
.expect;
sleep;
child.kill.expect;
let status = child.wait.expect;
if status.success else
The status
function spawns a child process, waits for
it to finish and returns its ExitStatus
.
use Command;
let status = new
.status
.expect;
if status.success else