Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I couldn't run "cls" with std::pocces::Command. #95957

Closed
Oya-Tomo opened this issue Apr 12, 2022 · 5 comments
Closed

I couldn't run "cls" with std::pocces::Command. #95957

Oya-Tomo opened this issue Apr 12, 2022 · 5 comments

Comments

@Oya-Tomo
Copy link

Error description

I tried to execute cls in powershell with std::pocces::Command . But it didn't work.
I can build my code, but when I try to run the exe I get an error.
Please tell me the solution to this problem?
I'm sorry I'm not good at English.

Environment

  • windows11
  • rustc 1.60.0 (installed using scoop)
  • cargo 1.60.0

code

use std::process::Command;

fn main() {
    Command::new("cls").status().expect("failed");
}

Error message

thread 'main' panicked at 'failed: Error { kind: NotFound, message: "program not found" }', src\main.rs:4:34
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@wwylele
Copy link
Contributor

wwylele commented Apr 12, 2022

cls isn't a program. It is a shell command of Windows cmd/powershell. std::process::Command doesn't run through any shell, and doesn't interpret any shell commands.

@Oya-Tomo
Copy link
Author

Oya-Tomo commented Apr 12, 2022

Thank you for your response.☺

Your answer is that Rust can't execute Windows commands, right?
I'm making a cli text editor. So, I need to clear the console lines.
Can you tell me how to clear the console?

@name1e5s
Copy link
Contributor

Thank you for your response.☺

Your answer is that Rust can't execute Windows commands, right? I'm making a cli text editor. So, I need to clear the console lines. Can you tell me how to clear the console?

You may instead use Command::new("cmd").arg("/C").arg("cls") to clear the console.

@Oya-Tomo
Copy link
Author

Thank you for your kind answer !
My problem was resolved.😀

@Dylan-DPC
Copy link
Member

Closing this as issue has been resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants