Solved

Error using Set (displayed but not functional error)

Posted on 2004-08-17
7
147 Views
Last Modified: 2012-05-05
I'm writing a batch file to automate running some SQL scripts.  It works great.  However, echo's an error message every time I call the set command. The command works, and functionally it does not cause any problems, but I'm curious why there is this error (and ideally what I need to do to get rid of it)

The error is:

  The system cannot find the drive specified.

This occurs on lines like this one:

  Set ParamValue=!FullPath!

Usually this is happening within an If block or a For block.

Any ideas?

Thanks!
Teiwaz
0
Comment
Question by:teiwaz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 1

Expert Comment

by:Tezdread
ID: 11826554
Not saying that I'll be able to help but could you post the rest of the code to give a clearer picture of what's happening?
0
 
LVL 17

Expert Comment

by:Eagle6990
ID: 11831644
What is !FullPath!  

0
 
LVL 1

Author Comment

by:teiwaz
ID: 11836329
Sorry for the delay, here is a sample script that has this behaviour.

And !FullPath! is an environment variable that is within a for loop and is using delayed expansion. %FullPath% does not show the value of the environment variable within a For if the value changes within that for block.

While trying to get a script that just shows the error (my full script is rather long), I found out that the error is being caused by a combination of comment lines, not the Set command!

The comments are:

  :: Build the parameter replacement command for sed for this parameter
  :: Special Case 1: CmdDir

If either of the lines is removed, no error.  weird.

Here is the full script:
<start>

:: Weird Error example
@echo off
:: This is an example script showing how a weird error is caused

Echo My System Info
ver
echo.

Setlocal EnableDelayedExpansion

:: An error will be raised here when the script hits the embedded comments
for /L %%i IN (1,1,10) Do (
  Echo i is %%i
  Echo before comment
  :: Build the parameter replacement command for sed for this parameter
  :: Special Case 1: CmdDir
  echo after comment
  echo.  
)
EndLocal
Goto :eof

<end>

After you run this, try removing either of the comment lines.  Only the combination causes error.  Any idea why?

Thanks!
Teiwaz
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 85

Accepted Solution

by:
oBdA earned 500 total points
ID: 11845672
That's mainly because the "::" construction actually isn't a comment.
A real comment starts with "REM"; the "::" construction is usually used because a line starting with a colon is considered a label, and it's ignored by the parser when processing it--unlike the REM lines, which are processed (turn the echo on, and you'll see it). That saves a bit of time. The double colon :: is, as far as I know, just the common way to designate this as a remark; using a single colon will work as well (in fact, if you start your "remarked" lines either with a single colon, or with a REM, the error will disappear as well).
Why exactly it's happening, I can't tell; that's hidden in the mysterious ways the parser works.
Another way to get rid of long bracket constructions is to use the batch version of a subroutine with "call :label" (enter "help call" for more information).

@echo off
:: This is an example script showing how a weird error is caused

Echo My System Info
ver
echo.

Setlocal EnableDelayedExpansion

:: An error will be raised here when the script hits the embedded comments
for /L %%i IN (1,1,10) Do (
  set Count=%%i
  call :process1
)
for /L %%i IN (1,1,10) Do call :process2 %%i
EndLocal
Goto :leave

:process1
Echo Count is %Count%
Echo before comment
:: Build the parameter replacement command for sed for this parameter
:: Special Case 1: CmdDir
echo after comment
echo.  
goto :eof

:process2
set Count=%1
Echo Count is %Count%
Echo before comment
:: Build the parameter replacement command for sed for this parameter
:: Special Case 1: CmdDir
echo after comment
echo.  
goto :eof

:leave
0
 
LVL 1

Author Comment

by:teiwaz
ID: 11872815
Very interesting.  So this whole double colon thing for comments is just a short cut that programers have figured out?  I read at http://www.ss64.com/nt/rem.html that REM prevents most commands from executing, but double-colon prevent all of them from executing.  Looks like that information was not quite correct!

So, in summary, this is happening because:

  a) the double-colon commenting style is actually not a comment to the parser but a special case of a label
  b) this is caused because of some weird interaction in the parser of a label with in a bracketed set of commands

And this can be fixed by:

  - use sub-routines instead of large blocks of code
  - try using single colons
  - maybe try not having two lines together

That about it?

teiwaz
0
 
LVL 85

Expert Comment

by:oBdA
ID: 11875212
When I come to think about it, the double colon is actually an invalid label, since a label should consist of characters after the colon. So it seems to be the combination of a block and two illegal labels that causes the hickup.
And that's about it.
If in doubt, I'd go for the call :label solution, especially in for loops. That's very helpful as well in NT4, where the delayed expansion doesn't exist; you can circumvent this problem by jumping to a subroutine.
0
 
LVL 1

Author Comment

by:teiwaz
ID: 11875637
Thanks for the hlep oBda!
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
With the rising number of cyber attacks in recent years, keeping your personal data safe has become more important than ever. The tips outlined in this article will help you keep your identitfy safe.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question