The_Boom_Boy
The_Boom_Boy

Reputation: 1

Multiple spaces in command CMD

Ok so i am trying to flash a hex file onto my arduino pro micro following this sorta guide:

https://www.reddit.com/r/MechanicalKeyboards/comments/69woay/hand_built_keypad_gateron_blues_first_hand_wire/

And I am really struggling with step 2. The problem that i am having is that my thing (Not sure what to call it) looks like this:

""C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude" "-CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -v -patmega32u4 -cavr109 -PCOM5 -b57600 -D -Uflash:wC:"\Users\My Name\Desktop\Layout\layout.hex:i""

I am getting a this error:

'""C:\Program' is not recognized as an internal or external command,

operable program or batch file.

Which i tried fixing with the speech marks following these recommendations:

How do I specify C:\Program Files without a space in it for programs that can't handle spaces in file paths?

How to use spaces in CMD?

So that's the issue i am probably making one minor mistake or many major ones, but you help would be greatly appreciated.

Upvotes: 0

Views: 1619

Answers (2)

slim
slim

Reputation: 41263

Let's look at a simpler example. You might try to run C:\Program Files (x86)\myapp\myprogram like this:

C:\Program Files (x86)\myapp\myprogram --parameter:value

It doesn't work because the first thing CMD does is split on spaces. This is called *tokenisation` and the result is a list of tokens:

  • C:\Program
  • Files
  • (x86)\myapp\myprogram
  • --parameter:value

Then it takes the first token, C:\Program and tries to find a file with that name.

'C:\Program' is not recognized as an internal or external command

The tokenisation routine pays attention to quotes. When it encounters a quote, it strips it, then it doesn't treat spaces as token separators, until it encounters the next quote.

So:

"C:\Program Files (x86)\myapp\myprogram" --parameter:value

Tokenises to:

  • C:\Program Files (x86)\myapp\myprogram
  • --parameter:value

For some reason in your example you have put more quotes around the whole thing:

""C:\Program Files (x86)\myapp\myprogram" --parameter:value"

Tokenisation treats the double " as a literal "", so now it tokenises to:

  • ""C:\Program Files
  • (x86)\myapp\myprogram
  • --parameter:value

So you get an error because there is no executable file ""C:\Program Files.

Understand how quoting and tokenisation works. Make sense of the commands rather than blindly copying them, and you should be able to solve this.

Upvotes: 2

Andreas
Andreas

Reputation: 94

Let's analyze your string

""C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude" "-CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -v -patmega32u4 -cavr109 -PCOM5 -b57600 -D -Uflash:wC:"\Users\My Name\Desktop\Layout\layout.hex:i""

The problem occurs right away with your double quote "". This is interpreted as an empty string between these two quotes. Thus making your C:\Program Files end up outside quotes.

Try this instead

"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude" "-CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -v -patmega32u4 -cavr109 -PCOM5 -b57600 -D -Uflash:wC:"\Users\My Name\Desktop\Layout\layout.hex:i"

Upvotes: 1

Related Questions