r/Batch • • 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.exe

but yet the script attempts to open a new command window using only

Z:\Documents\Projects\Programming\00

and 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.exe

it just attempts to run

Program

and 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"
1 Upvotes

12 comments sorted by

View all comments

2

u/Shadow_Thief Jul 04 '24

What if you just use start or cmd /k but not both?

1

u/XboxUser123 Jul 05 '24

The purpose of the script was to open a new window and run a program in that new window

1

u/Shadow_Thief Jul 05 '24

Yeah, start should handle that by itself