tags:

views:

70

answers:

5

Running the following example 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 tagged, this question is dealing with Windows (XP) batch files.

A: 

Try removing the ampersands.

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

I get

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

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

edit - I didn't have @echo off at the top of my batch file.

kmfk
If you remove the ampersands you change the behavior of the commands. The ampersands indicate that the second command should only run if the first command succeeds.
bobs
kmfk
yes, that is true if you run it from a cmd line. The question indicates it should be in a batch file. It works differently in the batch file.
bobs
no, I mean, I created this batch file and ran it from my desktop and received the echo indicated above. Im running windows 7 currently... could be the difference.
kmfk
A: 

You need to quote the path if it contains spaces; I'm not quite sure what language you're dealing with, but basically you need:

""C:\Program Files\Internet Explorer\iexplore.exe""
DanP
Windows (XP) batch file. New error:'""C:\Program' is not recognized as an internal or external command,operable program or batch file.
steamer25
A: 

Try putting && on the second line.

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

Edit: As the Question asks, this command must be run in a batch file. It works from the batch file but works incorrectly at the command line!

bobs
Wimmel
This command works correctly if you put it in the batch file as the OP indicated. Please try the command in a batch file.
bobs
+1  A: 

Quotation marks do seem to be properly parsed by cmd.exe when they are preceded by conditional processing symbols (i.e., &, &&, ||).

As a work-around you can use a path that contains short names only without white space characters:

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

Or use a helper variable with delayed variable expansion:

setlocal enabledelayedexpansion

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

echo foo &&^
!IE_EXE!
sakra
second solution sends a wrong commandline to iexplore. It will try to open `http://files/Internet%20Explorer/iexplore.exe`
Wimmel
A: 

This seems to work too:

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