Constructing String from &[u8] yields mysterious `12` instead of whitespaces?

Hi I am trying to capture a CLI output it appears that some certain codepoint is not being read properly? How can I fix it?

https://hastebin.com/raw/lawowawoge

Contents of the link:

Summary

pub fn generate_inxi_report(omit_sensitive_information: bool) -> String {
let mut inxi_args = vec!["-F", "-v8"];
if omit_sensitive_information {
inxi_args.push("-Z");
}

let result = String::from_utf8(
    std::process::Command::new("inxi")
        .args(&inxi_args)
        .output()
        .unwrap()
        .stdout,
)
.unwrap();

#[cfg(debug_assertions)]
println!("{}", result);

result

}

////////// Outputs //////////

(process:3552): Gtk-WARNING **: 18:53:51.190: Locale not supported by C library.
Using the fallback 'C' locale.
12System: 12Host primarypc 12Kernel 4.19.66-1-MANJARO x86_64 12bits 64 12compiler gcc 12v 9.1.0
12parameters BOOT_IMAGE=/boot/vmlinuz-4.19-x86_64
root=UUID=5af4849f-74dc-4742-ad54-be5f2734cac3 rw quiet
12Desktop Gnome 3.32.2 12wm gnome-shell 12dm GDM 3.32.0 12Distro Manjaro Linux
12Machine: 12Type Desktop 12Mobo Micro-Star 12model B350 TOMAHAWK (MS-7A34) 12v 1.0 12serial
12UEFI American Megatrends 12v 1.M0 12date 01/23/2019
12Memory: 12RAM 12total 7.80 GiB 12used 3.65 GiB (46.8%)
12RAM Report 12permissions Unable to run dmidecode. Root privileges required.
12PCI Slots: 12Permissions Unable to run dmidecode. Root privileges required.
12CPU: 12Topology 8-Core 12model AMD Ryzen 7 1700X 12bits 64 12type MT MCP 12arch Zen 12family 17 (23)
12model-id 1 12stepping 1 12microcode 8001137 12L2 cache 4096 KiB 12bogomips 108825
12Speed 2314 MHz 12min/max 2200/3400 MHz 12boost enabled 12Core speeds (MHz) 121 2309 122 2176
123 2401 124 2412 125 1692 126 1712 127 1713 128 1713 129 2806 1210 2802 1211 2336 1212 2341 1213 2339
1214 2342 1215 1712 1216 1709
12Flags 3dnowprefetch abm adx aes aperfmperf apic arat avic avx avx2 bmi1 bmi2 bpext
clflush clflushopt clzero cmov cmp_legacy constant_tsc cpb cpuid cr8_legacy cx16 cx8 de
decodeassists extapic extd_apicid f16c flushbyasid fma fpu fsgsbase fxsr fxsr_opt ht
hw_pstate ibpb irperf lahf_lm lbrv lm mca mce misalignsse mmx mmxext monitor movbe msr
mtrr mwaitx nonstop_tsc nopl npt nrip_save nx osvw overflow_recov pae pat pausefilter
pclmulqdq pdpe1gb perfctr_core perfctr_llc perfctr_nb pfthreshold pge pni popcnt pse
pse36 rdrand rdseed rdtscp rep_good sep sev sha_ni skinit smap smca sme smep ssbd sse
sse2 sse4_1 sse4_2 sse4a ssse3 succor svm svm_lock syscall tce topoext tsc tsc_scale
v_vmsave_vmload vgif vmcb_clean vme vmmcall wdt xgetbv1 xsave xsavec xsaveerptr
xsaveopt xsaves
12Vulnerabilities 12Type l1tf 12status Not affected
12Type mds 12status Not affected
12Type meltdown 12status Not affected
12Type spec_store_bypass
12mitigation Speculative Store Bypass disabled via prctl and seccomp
12Type spectre_v1 12mitigation usercopy/swapgs barriers and __user pointer sanitization
12Type spectre_v2
12mitigation Full AMD retpoline, IBPB: conditional, STIBP: disabled, RSB filling
12Graphics: 12Device-1 AMD Ellesmere [Radeon RX 470/480/570/570X/580/580X/590]
12vendor Hightech Information System 12driver amdgpu 12v kernel 12bus ID 1c:00.0
12chip ID 1002:67df
12Display x11 12server X.org 1.20.5 12driver amdgpu 12compositor gnome-shell
12resolution
12OpenGL
12renderer Radeon RX 570 Series (POLARIS10 DRM 3.27.0 4.19.66-1-MANJARO LLVM 8.0.1)
12v 4.5 Mesa 19.1.4 12direct render Yes
12Audio: 12Device-1 AMD Ellesmere HDMI Audio [Radeon RX 470/480 / 570/580/590]
12vendor Hightech Information System 12driver snd_hda_intel 12v kernel 12bus ID 1c:00.1
12chip ID 1002:aaf0
12Device-2 AMD Family 17h HD Audio 12vendor Micro-Star MSI 12driver snd_hda_intel 12v kernel
12bus ID 1e:00.3 12chip ID 1022:1457
12Sound Server ALSA 12v k4.19.66-1-MANJARO
12Network: 12Device-1 Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet 12vendor Micro-Star MSI
12driver r8168 12v 8.047.02-NAPI 12port f000 12bus ID 19:00.0 12chip ID 10ec:8168
12IF enp25s0 12state down 12mac 4c:cc:6a:f4:2f:dc
12Device-2 Samsung GT-I9070 (network tethering USB debugging enabled) 12type USB
12driver rndis_host 12bus ID 3-1:6 12chip ID 04e8:6864 12serial R58M45MLS8W
12IF enp29s0f3u1 12state unknown 12speed N/A 12duplex N/A 12mac d2:2d:c4:7f:08:b2
12IP v4 192.168.42.68/24 12type dynamic noprefixroute 12scope global 12broadcast 192.168.42.255
12IP v6 fe80::f3fc:7578:3747:e13a/64 12type noprefixroute 12scope link
12WAN IP 121.91.81.32
12Drives: 12Local Storage 12total 2.84 TiB 12used 55.11 GiB (1.9%)
12ID-1 /dev/sda 12vendor Seagate 12model ST1000DM010-2EP102 12size 931.51 GiB 12block size
12physical 4096 B 12logical 512 B 12speed 6.0 Gb/s 12rotation 7200 rpm 12serial Z9AY0PE6 12rev CC43
12scheme GPT
12ID-2 /dev/sdb 12vendor Kingston 12model SUV400S37120G 12size 111.79 GiB 12block size
12physical 4096 B 12logical 512 B 12speed 6.0 Gb/s 12serial 50026B727303DB75 12rev 96R9
12scheme GPT
12ID-3 /dev/sdc 12type USB 12vendor Western Digital 12model WD20EZRZ-00Z5HB0 12size 1.82 TiB
12block size 12physical 512 B 12logical 512 B 12rotation 5400 rpm 12serial WD-WCC4M7DKCZFK
12rev 1065 12scheme MBR
12Message No Optical or Floppy data was found.
12RAID: 12Message No RAID data was found.
12Partition: 12ID-1 / 12raw size 111.49 GiB 12size 109.24 GiB (97.98%) 12used 21.31 GiB (19.5%) 12fs ext4
12dev /dev/sdb2 12label N/A 12uuid 5af4849f-74dc-4742-ad54-be5f2734cac3
12ID-2 /boot/efi 12raw size 300.0 MiB 12size 299.4 MiB (99.80%) 12used 280 KiB (0.1%) 12fs vfat
12dev /dev/sdb1 12label N/A 12uuid 82C3-CACE
12ID-3 /run/media/user0/521c8bca-c4eb-411c-ae0b-09f0163050ec 12raw size 694.0 MiB
12size 667.1 MiB (96.12%) 12used 1.4 MiB (0.2%) 12fs ext4 12dev /dev/sdc1 12label N/A
12uuid 521c8bca-c4eb-411c-ae0b-09f0163050ec
12ID-4 /run/media/user0/portable_drive 12raw size 1.82 TiB 12size 1.79 TiB (98.38%)
12used 33.80 GiB (1.8%) 12fs ext4 12dev /dev/sdc2 12label portable_drive
12uuid d500f0d8-2b8f-49af-929c-7206a6bcdc90
12ID-5 /var/lib/snapd/snap/atom/238 12raw size 219.0 MiB 12size
12used 12fs squashfs 12dev /dev/loop0 12label N/A 12uuid N/A
12ID-6 /var/lib/snapd/snap/code/13 12raw size 134.4 MiB 12size
12used 12fs squashfs 12dev /dev/loop2 12label N/A 12uuid N/A
12ID-7 /var/lib/snapd/snap/core/7396 12raw size 88.7 MiB 12size
12used 12fs squashfs 12dev /dev/loop1 12label N/A 12uuid N/A
12Unmounted: 12ID-1 /dev/sda1 12size 499.0 MiB 12fs ntfs 12label Recovery 12uuid 06D4A3CCD4A3BBF5
12ID-2 /dev/sda2 12size 100.0 MiB 12fs vfat 12label N/A 12uuid 0CA7-C0F9
12ID-3 /dev/sda3 12size 16.0 MiB 12fs 12label N/A 12uuid N/A
12ID-4 /dev/sda4 12size 930.91 GiB 12fs ntfs 12label N/A 12uuid 5AC0AE50C0AE3265
12USB: 12Hub 1-0:1 12info Full speed (or root) Hub 12ports 10 12rev 2.0 12speed 480 Mb/s
12chip ID 1d6b:0002
12Device-1 1-8:2 12info D-Link 12type 12driver N/A 12interfaces 1 12rev 2.1
12speed 480 Mb/s 12chip ID 2001:331c 12serial 123456
12Hub 2-0:1 12info Full speed (or root) Hub 12ports 4 12rev 3.1 12speed 10 Gb/s 12chip ID 1d6b:0003
12Hub 3-0:1 12info Full speed (or root) Hub 12ports 4 12rev 2.0 12speed 480 Mb/s
12chip ID 1d6b:0002
12Device-2 3-1:6 12info Samsung GT-I9070 (network tethering USB debugging enabled)
12type Bluetooth,CDC-Data 12driver rndis_host 12interfaces 3 12rev 2.0 12speed 480 Mb/s
12chip ID 04e8:6864 12serial R58M45MLS8W
12Device-3 3-2:3 12info Logitech Unifying Receiver 12type Keyboard,Mouse
12driver hid-generic,usbhid 12interfaces 2 12rev 2.0 12speed 12 Mb/s 12chip ID 046d:c534
12Hub 4-0:1 12info Full speed (or root) Hub 12ports 4 12rev 3.0 12speed 5 Gb/s 12chip ID 1d6b:0003
12Device-4 4-4:2 12info Western Digital My Book (WDBFJK) 12type Mass Storage
12driver usb-storage 12interfaces 1 12rev 3.0 12speed 5 Gb/s 12chip ID 1058:1230
12serial 574343344D37444B435A464B
12Sensors: 12System Temperatures 12cpu 47.9 C 12mobo N/A 12gpu amdgpu 12temp 45 C
12Fan Speeds (RPM) N/A 12gpu amdgpu 12fan 984
12Repos: 12Active pacman repo servers in /etc/pacman.d/mirrorlist
121 http: //manjaro.melbourneitmirror.net/stable/$repo/$arch
12Processes: 12CPU top 5
121 12cpu 4.6% 12command firefox 12pid 30066 12mem 805.3 MiB (10.0%)
122 12cpu 2.9% 12command firefox 12pid 28078 12mem 277.0 MiB (3.4%)
123 12cpu 2.7% 12command xorg 12pid 1111 12mem 215.2 MiB (2.6%)
124 12cpu 2.5% 12command target/debug/syspec 12pid 3552 12mem 21.4 MiB (0.2%)
125 12cpu 1.1% 12command firefox 12pid 30034 12mem 211.6 MiB (2.6%)
12Memory top 5
121 12mem 805.3 MiB (10.0%) 12command firefox 12pid 30066 12cpu 4.6%
122 12mem 521.3 MiB (6.5%) 12command gnome-shell 12pid 1216 12cpu 0.8%
123 12mem 392.4 MiB (4.9%) 12command firefox 12pid 30198 12cpu 0.3%
124 12mem 310.8 MiB (3.8%) 12command rls 12pid 17166 12cpu 0.2%
125 12mem 277.0 MiB (3.4%) 12command firefox 12pid 28078 12cpu 2.9%
12Info: 12Processes 375 12Uptime 7d 22h 23m 12Init systemd 12v 242 12Compilers 12gcc 9.1.0 12clang 8.0.1
12Client Unknown Client: syspec 12inxi 3.0.35

Locale not supported by C library.
Using the fallback 'C' locale.

Looks like the output might not actually be utf-8?

I don't think that's the case. This warning is generated from the gtk-rs library. I tested it without a gtk-rs project and the warning goes away yet it still gives me

that 12.

It seems color sequence is read (maybe partially or incorrectly?).
You seem to have to disable colored formatting or to remove color sequences manually from the output.

EDIT: Color can be disabled by -c 0 option.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.