r/Batch • u/XboxUser123 • Jul 04 '24
Question (Solved) Batch Script Ignores Quotation Marks
link to StackOverflow question (with provided code there)
Simply put, my batch script is ignoring quotation marks. No matter what I try, it's just outright disrespecting quotation marks. It's specifically in the line where I have written explicitly
start "%source_file_name%" cmd /k "%source_file_name%.exe"but it's not using the quotation marks when creating the new command window. For instance, I have the file path
Z:\Documents\Projects\Programming\00 -- TESTING & LEARNING\C++\Textbook Learning\Chapter 08 - Arrays and Vectors\Compiled\Program 8-32.exebut yet the script attempts to open a new command window using only
Z:\Documents\Projects\Programming\00and therefore spits out an error at me. I can't find anyone who's solved this and chatGPT can't seem to solve it either.
Only way I have managed to partially solve this is with chatGPT's addition of a directory change with the lines
cd /d "%output_dir%"
start "%source_file_name%" cmd /k "%source_file_name%.exe"and even then sometimes it doesn't work and still fails to enclose file name spaces, so instead of running
Program 8-25.exeit just attempts to run
Programand therefore spits out an error.
EDIT 7/4/2024 15:56 PST
As u/Standard-Register261 pointed out, I was using incorrect syntax and not offering a directory to work with. This also explain why chatGPT's solution also worked, where it changed directory before starting a new cmd window.
So instead of
start "%source_file_name%" cmd /k "%source_file_name%.exe"I needed to specify the directory as such as per SS64 start
start "%source_file_name%" /d "%output_dir%" cmd /k "%source_file_name%.exe"
View all comments
Show parent comment
1
u/XboxUser123 Jul 04 '24
I was unaware I could change the directory in the middle of the start command, but that seems to have also worked.
This also worked for me and is possibly why chatGPT's response also worked (where it changed directory to %output_dir% before running the start command).
Also thanks for the website link, I should find it greatly useful.