draft of pwdx
This commit is contained in:
parent
8bba913e56
commit
7163749b04
src/uu/pwdx
12
src/uu/pwdx/Cargo.toml
Normal file
12
src/uu/pwdx/Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "uu_pwdx"
|
||||||
|
version = "0.0.1"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "pwdx"
|
||||||
|
path = "src/pwdx.rs"
|
24
src/uu/pwdx/src/pwdx.rs
Normal file
24
src/uu/pwdx/src/pwdx.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs;
|
||||||
|
use std::path::Path;
|
||||||
|
use std::process;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let args: Vec<String> = env::args().collect();
|
||||||
|
|
||||||
|
if args.len() != 2 {
|
||||||
|
eprintln!("Usage: pwdx <pid>");
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let pid = &args[1];
|
||||||
|
let cwd_link = format!("/proc/{}/cwd", pid);
|
||||||
|
|
||||||
|
match fs::read_link(Path::new(&cwd_link)) {
|
||||||
|
Ok(path) => println!("{}: {}", pid, path.display()),
|
||||||
|
Err(e) => {
|
||||||
|
eprintln!("pwdx: failed to read link for PID {}: {}", pid, e);
|
||||||
|
process::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user