问题描述:
我在程序中使用了以下代码
let trace_status = Command::new("bpftrace")
.args(["-f", "json", "-o", "output.json", "source_files/test_trace.bt"])
.status()
.expect("Failed to run bpftrace");
并在expect处得到报错 code: 2, kind: NotFound, message: "No such file or directory"
已经检查了文件路径没有问题,当我用以下代码编译测试时,可以准确得到test_trace.bt
文件内容。
let trace_status = Command::new("cat")
.args(["source_files/test_trace.bt"])
.status()
.expect("Failed to run bpftrace");
并且当我在终端中直接运行sudo bpftrace source_file/test_trace.bt
时,也可以运行。* 代码中已经在之前获得了sudo,所以问题也不是在root权限
总结而言就是:唯独在代码中bpftrace指令无法找到文件,在代码中执行其他指令或在终端中执行bpftrace,都可以发现文件。
想请问一下有各位之前有谁遇到过类似情况的,劳烦给个思路,感谢