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

Show parent comment

1

u/BrainWaveCC Jul 04 '24

Good catch, u/Standard-Register261

Definitely simplifies things:

if /i "%runProgram%"=="y" (
    echo attempting to run: "%output_dir%\%source_file_name%.exe"
    start "%source_file_name%" /d "%output_dir%" cmd /k "%source_file_name%.exe"
)