commandspec icon indicating copy to clipboard operation
commandspec copied to clipboard

How to pass dynamic values?

Open p32929 opened this issue 3 years ago • 0 comments

Hi, thanks for maintaining the repository.

I've been trying to make a cli tool for myself where I can run series of commands & I found this repository. So, I tried this code:

execute!(
        r"
        cd C:\\Users\\MegaMind\\Documents\\dynamodb_local_latest
        dir
        ",
    ).unwrap();

and it works fine. But when I try to do this:

let cc = "cd C:\\Users\\MegaMind\\Documents\\dynamodb_local_latest";
let dd = "dir";

execute!(
	r"
	{cc}
	{dd}
	",
	cc=cc, dd=dd
).unwrap();

or this:

let commands = vec!["cd C:\\Users\\MegaMind\\Documents\\dynamodb_local_latest","ls"];
    execute!(
        r"
        {ccc}
        ", ccc=commands.join("\n")
    ).unwrap();

it gives this error:

'E:\SourceCodes\Rust\cmder\cd' is not recognized as an internal or external command,
operable program or batch file.
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Code(1)', src\main.rs:20:7
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\cmder.exe` (exit code: 101)

Any way to pass dynamic values into the execute function? Thanks

p32929 avatar Sep 24 '22 10:09 p32929