#Double quotes in string
64 messages · Page 1 of 1 (latest)
I think
Command::new(r"cd \"C:\Program Files (x86)\TmUnitedForever\" && \"C:\Program Files (x86)\TmUnitedForever\TMInterface.exe\"");
would work
don't quote me on that am new and dum
?eval r#""Hello, World!""#
Running `target/debug/playground`
"\"Hello, World!\""
?eval r#""cd "C:\Program Files (x86)\TmUnitedForever" && "C:\Program Files (x86)\TmUnitedForever\TMInterface.exe"""#
Running `target/debug/playground`
"\"cd \"C:\\Program Files (x86)\\TmUnitedForever\" && \"C:\\Program Files (x86)\\TmUnitedForever\\TMInterface.exe\"\""
either that or
?eval r#"cd "C:\Program Files (x86)\TmUnitedForever" && "C:\Program Files (x86)\TmUnitedForever\TMInterface.exe""#
Running `target/debug/playground`
"cd \"C:\\Program Files (x86)\\TmUnitedForever\" && \"C:\\Program Files (x86)\\TmUnitedForever\\TMInterface.exe\""
should work
#+ can be added around raw strings, as effectively additional string deliminators.
?eval println!(r#""Hello, World!""#)
Running `target/debug/playground`
"Hello, World!"
()
?eval rs println!("Hello, \ World!")
Running `target/debug/playground`
Hello, World!
()
Oop- 😹
Show us what you tried.
Also, \ before a newline, will truncate all the whitespace following,
(Makes it a little easier to read when writing out long strings...)
The ; will bind the result of new() to output
I assume so, but does the directory exist?
@earnest halo as a note, when working with paths, unless you're targeting some ancient windows version, I'd recommend just using unix-style slashes
/
C:/Users/user is a valid path on windows
and means you don't have to deal with escaping issues with backslashes in paths
what's the current error?
just gonna double check...
?eval r#"cd "C:/Program Files (x86)/TmUnitedForever" && "C:/Program Files (x86)/TmUnitedForever/TMInterface.exe""#
Running `target/debug/playground`
"cd \"C:/Program Files (x86)/TmUnitedForever\" && \"C:/Program Files (x86)/TmUnitedForever/TMInterface.exe\""
oh
that bug
yeah ok so this isn't a bug, it's just not clear
@earnest halo do you need to be in the same directory as TMInterface.exe?
is the cd necessary?
mm ok
so basically
the reason you're getting that panic
is that cd doesn't exist
cd is a command in cmd
not an executable in path
eg
yes I'm sure
C:\Users\legor>where cd
INFO: Could not find files for the given pattern(s).
so basically, Command requires an actual executable
and iirc it doesn't actually use PATH either
so you need your working directory for your program to be C:/Program Files (x86)/TmUnitedForever?
use std::env;
use std::path::Path;
use std::process::Command;
fn main() {
let mut root = Path::new("C:/Program Files (x86)/TmUnitedForever").to_owned();
// Change working directory
env::set_current_dir(&root).unwrap();
// Add TMInterface.exe onto our root path
root.push("TMInterface.exe");
// Execute the command
let output = Command::new(root).output().expect("Failed to execute program.");
println!("{}", String::from_utf8(output.stdout).unwrap());
}
@earnest halo that should do the job
that code should boot your game
ah I got my news confused, lol
@earnest halo I edited, try now
np :P
so basically
you understand what all the individual parts of that program are doing?
epic :P
make sure to try and use Path or PathBuf whenever you're handling paths, too
Alternatively, there's also a current_dir() method, to define where the process will execute...
use std::{
process::Command,
io,
};
fn main() -> io::Result<()> {
// Specify executable
Command::new("TMInterface.exe")
// Specify directory to run from
.current_dir("C:/Program Files (x86)/TmUnitedForever")
// Execute process
.output()
// Attempt conversion of output to string
.map(|output| String::from_utf8(output.stdout).unwrap())
// Print output, and return sucess state
.map(|output| println!("{output}"))
}```
Nah, ignore me... current_dir() doesn't define where it'll look for the binary...