replace --> println!("Output:{} ", String::from_utf8_unchecked(o.stdout)); with --> println!("Output:{} ", String::from_utf8_lossy(&o.stdout)); and you don't need the unsafe block Thumbs up
Is it possible that the language has changed a lot since? When I tried to get to the Err(e) branch by renaming the target file, it did not go there, instead it was still Ok, with the following structure: Output { status: ExitStatus(ExitStatus(32512)), stdout: "", stderr: "bash: simple.sh: No such file or directory " } (the program was slightly modified: instead of python, it was executing bash) When the file is found: Output { status: ExitStatus(ExitStatus(0)), stdout: "Hello, Bash World! ", stderr: "" }
I think that's not an Error state from Rust's perspective, the command caused an error when you ran it on the system but since the command successfully spawned and returned its output (the error message) the actual command call was "ok"
Hi, many thanks for this tutorial, I really appreciate the series and the great job you made. Two things: - I am just surprised you could manage to run your Python code without any issue; normally Python - at least version 3 - makes use of parenthesis mandatory for print instructions like this => print("Hello I am from Python!") - o.stdout actually prints the corresponding ASCII codes: [72, 101, 108, 108, 111, 32, 73, 32, 97, 109, 32, 102, 114, 111, 109, 32, 80, 121, 116, 104, 111, 110, 33, 10] But to be fair: maybe things have changed since you made this tutorial two years ago. Again: great job.
Demonstrating using 'unsafe' in a tutorial is highly irresponsible. Unsafe is a feature designed for advanced practices sacrificing most of the advantages of the language when absolutely necessary. Just throwing it in there without discussing its risks when you can assume most people watching this are fairly new to programming and Rust especially is a horrible, horrible teaching practice
don't panic ;-) Using the unsafe block for a tutorial about process is absolutely fine. This is not the purpose of this subject. And in rust you literary type UNSAFE and btw Dcode mention it. So no problem at all.
replace --> println!("Output:{} ", String::from_utf8_unchecked(o.stdout));
with --> println!("Output:{} ", String::from_utf8_lossy(&o.stdout));
and you don't need the unsafe block
Thumbs up
Or, String::from_utf8(o.stdout).unwrap() to get it to panic if the output wasn't valid UTF-8. Or use "if let" or "match" to check whether it was Ok.
lets say the python script has an input, & I wanna serve the input value from rust. is there any way to do it? thanks
Thanks this is exactly the thing I've been looking for. I have a plan involving generating a batch file and then running it within a rust program.
Thank you man, you explain things so clearly ;)
Is it possible that the language has changed a lot since? When I tried to get to the Err(e) branch by renaming the target file, it did not go there, instead it was still Ok, with the following structure:
Output { status: ExitStatus(ExitStatus(32512)), stdout: "", stderr: "bash: simple.sh: No such file or directory
" }
(the program was slightly modified: instead of python, it was executing bash)
When the file is found:
Output { status: ExitStatus(ExitStatus(0)), stdout: "Hello, Bash World!
", stderr: "" }
I think that's not an Error state from Rust's perspective, the command caused an error when you ran it on the system but since the command successfully spawned and returned its output (the error message) the actual command call was "ok"
Very gooooooddddd, continue with playlist.
Oh great, I was just looking for this. Thanks!!
Hi, many thanks for this tutorial, I really appreciate the series and the great job you made.
Two things:
- I am just surprised you could manage to run your Python code without any issue; normally Python - at least version 3 - makes use of parenthesis mandatory for print instructions like this => print("Hello I am from Python!")
- o.stdout actually prints the corresponding ASCII codes: [72, 101, 108, 108, 111, 32, 73, 32, 97, 109, 32, 102, 114, 111, 109, 32, 80, 121, 116, 104, 111, 110, 33, 10]
But to be fair: maybe things have changed since you made this tutorial two years ago.
Again: great job.
Demonstrating using 'unsafe' in a tutorial is highly irresponsible. Unsafe is a feature designed for advanced practices sacrificing most of the advantages of the language when absolutely necessary. Just throwing it in there without discussing its risks when you can assume most people watching this are fairly new to programming and Rust especially is a horrible, horrible teaching practice
don't panic ;-)
Using the unsafe block for a tutorial about process is absolutely fine. This is not the purpose of this subject.
And in rust you literary type UNSAFE and btw Dcode mention it.
So no problem at all.
Calm down.
Omg ... The nuclear reactor next door is gonna blow up 😱
Programming is in itself unsafe because your brain might explode from all the confusion.
Maybe some things do need to be said in harsh words.