如何检测 Rust 产生的命令是否导致分段错误?
我正在努力构建一个包装器,以测试偶尔导致细分故障的应用程序。
use std::io::{Write};
use std::process::{Command, Stdio};
fn main() {
let input_name = "Saqib Ali";
let input_email = "[email protected]"
let input_serial_numer = "SN103213112"
let register_app = Command::new("register_drive").stdin(Stdio::piped()).spawn().unwrap();
write!(register_app.stdin.unwrap(), "{}", input_name).unwrap();
}
当input_name
发送到它时,如何检测程序是否导致细分故障?
I am working to build a wrapper to test an application that occasionally results in a Segmentation Fault.
use std::io::{Write};
use std::process::{Command, Stdio};
fn main() {
let input_name = "Saqib Ali";
let input_email = "[email protected]"
let input_serial_numer = "SN103213112"
let register_app = Command::new("register_drive").stdin(Stdio::piped()).spawn().unwrap();
write!(register_app.stdin.unwrap(), "{}", input_name).unwrap();
}
How do I detect if a program resulted in Segmentation Fault when a input_name
was sent to it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以等待该过程完成,然后使用 Unix 特定的
ExitStatusExt
特征从退出状态中提取信号代码,并使用libc
包将信号标识为 <代码>SIGSEGV:Playground
请注意,您可能想要使用 writeln!() 写入程序的标准输入,否则具有输入名称的行不会终止,并且可能会与后续输入合并。
You can wait for the process to finish and use the Unix-specific
ExitStatusExt
trait to extract the signal code out of the exit status and thelibc
crate to identify the signal asSIGSEGV
:Playground
Note that you might want to use
writeln!()
to write to the program's stdin, otherwise the line with the input name won't be terminated and might get merged with subsequent input.