Rust Programming Tutorial #40 - Running/Executing Commands (CLI)

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 ธ.ค. 2024

ความคิดเห็น • 25

  • @tim46767
    @tim46767 5 ปีที่แล้ว +28

    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

    • @markday3145
      @markday3145 4 ปีที่แล้ว +5

      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.

  • @fayaz2956
    @fayaz2956 2 ปีที่แล้ว +1

    lets say the python script has an input, & I wanna serve the input value from rust. is there any way to do it? thanks

  • @chastitywhiterose
    @chastitywhiterose 5 ปีที่แล้ว +1

    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.

  • @DaDa-gr7cy
    @DaDa-gr7cy 3 ปีที่แล้ว +1

    Thank you man, you explain things so clearly ;)

  • @silurust
    @silurust 4 ปีที่แล้ว

    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: "" }

    • @DOPEBEATZBOYS
      @DOPEBEATZBOYS 4 ปีที่แล้ว +1

      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"

  • @zaaita
    @zaaita 4 ปีที่แล้ว +1

    Very gooooooddddd, continue with playlist.

  • @PCB389
    @PCB389 2 ปีที่แล้ว

    Oh great, I was just looking for this. Thanks!!

  • @canardeur8390
    @canardeur8390 4 ปีที่แล้ว

    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.

  • @tetlamed
    @tetlamed 6 ปีที่แล้ว +17

    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

    • @tim46767
      @tim46767 5 ปีที่แล้ว +7

      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.

    • @elgs1980
      @elgs1980 5 ปีที่แล้ว +5

      Calm down.

    • @mahmoudfathy2074
      @mahmoudfathy2074 5 ปีที่แล้ว +7

      Omg ... The nuclear reactor next door is gonna blow up 😱

    • @chastitywhiterose
      @chastitywhiterose 5 ปีที่แล้ว

      Programming is in itself unsafe because your brain might explode from all the confusion.

    • @ChipAltmanxD
      @ChipAltmanxD 4 ปีที่แล้ว +3

      Maybe some things do need to be said in harsh words.