#Double quotes in string

64 messages · Page 1 of 1 (latest)

honest skiff
#

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

drifting wave
#

?eval r#""Hello, World!""#

lean owlBOT
#
     Running `target/debug/playground`

"\"Hello, World!\""
honest skiff
#

?eval r#""cd "C:\Program Files (x86)\TmUnitedForever" && "C:\Program Files (x86)\TmUnitedForever\TMInterface.exe"""#

lean owlBOT
#
     Running `target/debug/playground`

"\"cd \"C:\\Program Files (x86)\\TmUnitedForever\" && \"C:\\Program Files (x86)\\TmUnitedForever\\TMInterface.exe\"\""
honest skiff
#

either that or

#

?eval r#"cd "C:\Program Files (x86)\TmUnitedForever" && "C:\Program Files (x86)\TmUnitedForever\TMInterface.exe""#

lean owlBOT
#
     Running `target/debug/playground`

"cd \"C:\\Program Files (x86)\\TmUnitedForever\" && \"C:\\Program Files (x86)\\TmUnitedForever\\TMInterface.exe\""
honest skiff
#

should work

drifting wave
#

#+ can be added around raw strings, as effectively additional string deliminators.

#

?eval println!(r#""Hello, World!""#)

lean owlBOT
#
     Running `target/debug/playground`

"Hello, World!"
()
drifting wave
#

?eval rs println!("Hello, \ World!")

lean owlBOT
#
     Running `target/debug/playground`

Hello, World!
()
drifting wave
#

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...)

honest skiff
#

because you have a ;

drifting wave
#

The ; will bind the result of new() to output

honest skiff
#

I assume so, but does the directory exist?

civic steppe
#

@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?

honest skiff
#

just gonna double check...

#

?eval r#"cd "C:/Program Files (x86)/TmUnitedForever" && "C:/Program Files (x86)/TmUnitedForever/TMInterface.exe""#

lean owlBOT
#
     Running `target/debug/playground`

"cd \"C:/Program Files (x86)/TmUnitedForever\" && \"C:/Program Files (x86)/TmUnitedForever/TMInterface.exe\""
civic steppe
#

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

civic steppe
#

np :P feel free to ask questions on this server

#

we're all happy to help

drifting wave
#

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}"))
}```
drifting wave
#

Nah, ignore me... current_dir() doesn't define where it'll look for the binary...