How to avoid the quoted command after continuing the line?

By running the following sample batch file,

echo foo &&^
"C:\Program Files\Internet Explorer\iexplore.exe"

... produces the following output:

foo
'"C:\Program' is not recognized as an internal or external command,
operable program or batch file.

What am I missing?

EDIT

As noted, this question relates to Windows batch files (XP).

+3
source share
6 answers

Sorry, but almost all answers are incorrect or do not understand what is happening.

The problem does not depend on the cmd line or if it is inside the batch file.

Rule for a multi-line carriage character:
A carriage at the end of a line adds the next line and eludes the first character of the added line!
This is the reason you got

echo foo ^
&& echo bar
---- OUTPUT ---
foo &
bar
---------------

rem equivalent to
echo foo ^&& echo bar
rem So the first ampersand is escaped and the second works as a single &

,

echo foo &&^
"C:\Program Files\Internet Explorer\iexplore.exe"

rem is equivalent to this, so the quote will be escaped
echo foo &&^"C:\Program Files\Internet Explorer\iexplore.exe"

?

echo foo &&^
cmd /c "C:\Program Files\Internet Explorer\iexplore.exe"

rem is equivalent to
echo foo &&^cmd /c "C:\Program Files\Internet Explorer\iexplore.exe"

"c" , "cmd".

.

echo foo && >con ^
"C:\Program Files\Internet Explorer\iexplore.exe"

, , . ( , cmd.exe , ).

+7

cmd.exe, (.. &, &&, ||).

, :

echo foo &&^
C:\Progra~1\Intern~1\iexplore.exe

:

setlocal enabledelayedexpansion

set "IE_EXE=C:\Program Files\Internet Explorer\iexplore.exe"

echo foo &&^
!IE_EXE!
+1

:

echo foo &&^
cmd /c "C:\Program Files\Internet Explorer\iexplore.exe"
+1

&& .

echo foo ^
&& "C:\Program files\internet explorer\iexplore.exe"

: , . , !

0

.

echo foo ^ 
"C:\Program Files\Internet Explorer\iexplore.exe"

C:\Users\keith\Desktop>echo foo
foo

C:\Users\keith\Desktop>"C:\Program Files\Internet Explorer\iexplore.exe"

edit - @echo off .

-1

, ; , , :

""C:\Program Files\Internet Explorer\iexplore.exe""
-1

Source: https://habr.com/ru/post/1757717/


All Articles