Skip to content

Commit

Permalink
add shell_cmd.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
raghav-rama committed Apr 23, 2024
1 parent 3bf0e0b commit 302bb83
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/bin/shell_cmd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use std::io::{self, Write};
use std::process::Command;

fn main() {
// Specify the shell command to run
let command = "ls";

// Create a Command instance
let output = Command::new("sh")
.arg("-c")
.arg(command)
.output()
.expect("Failed to execute command");

// Print the command output
io::stdout().write_all(&output.stdout).unwrap();

// Print the command error (if any)
io::stderr().write_all(&output.stderr).unwrap();
}

0 comments on commit 302bb83

Please sign in to comment.