Update python_util.rs

This commit is contained in:
Shunsuke Shibayama 2022-08-11 12:07:52 +09:00
parent 2f881f1398
commit 1f07d8fc1a

View file

@ -11,10 +11,14 @@ pub fn which_python() -> String {
.arg(python) .arg(python)
.output() .output()
.expect("python not found"); .expect("python not found");
String::from_utf8(out.stdout) let res = String::from_utf8(out.stdout)
.unwrap() .unwrap()
.replace("\n", "") .replace("\n", "")
.replace("\r", "") .replace("\r", "");
if res == "" {
panic!("python not found");
}
res
} }
pub fn detect_magic_number() -> u32 { pub fn detect_magic_number() -> u32 {
@ -28,7 +32,6 @@ pub fn detect_magic_number() -> u32 {
.output() .output()
.expect("cannot get the magic number from python"); .expect("cannot get the magic number from python");
let s_hex_magic_num = String::from_utf8(out.stdout).unwrap(); let s_hex_magic_num = String::from_utf8(out.stdout).unwrap();
dbg!(&s_hex_magic_num);
let first_byte = u8::from_str_radix(&s_hex_magic_num[0..=1], 16).unwrap(); let first_byte = u8::from_str_radix(&s_hex_magic_num[0..=1], 16).unwrap();
let second_byte = u8::from_str_radix(&s_hex_magic_num[2..=3], 16).unwrap(); let second_byte = u8::from_str_radix(&s_hex_magic_num[2..=3], 16).unwrap();
get_magic_num_from_bytes(&[first_byte, second_byte, 0, 0]) get_magic_num_from_bytes(&[first_byte, second_byte, 0, 0])