是否可以在rust中作为进程运行函数?
rust是否可以在rust中作为进程运行函数?,rust,Rust,ruststd::process::Command;结构接受一个命令::new(program),其中program是要执行的程序的路径,如下例所示 let output = if cfg!(target_os = "windows") { Command::new("cmd") .args(&["/C", "echo hello"]) .output() .expect("failed to execute
std::process::Command
;结构接受一个命令::new(program)
,其中program是要执行的程序的路径,如下例所示
let output = if cfg!(target_os = "windows") {
Command::new("cmd")
.args(&["/C", "echo hello"])
.output()
.expect("failed to execute process")
是否可以在rust中的windows上创建一个新进程来运行函数?简而言之,您不能,创建一个新进程需要更多的信息,而不仅仅是它将执行的代码。请参阅Windows的系统调用 但是,您可以在以下备选方案中进行选择:
如果您在兼容平台上,并且对
fork
稍有了解,则可以使用。我无法找到Python的多处理.Process
的更高级别接口。这就引出了一个关键问题。作为一个函数,不一定像进程那样有状态返回码。。。你确定你需要的是进程而不是线程吗?