Solved

How to identify the path in batch file - %Variable%

Posted on 2011-09-15
5
353 Views
Last Modified: 2012-06-21
I'm working on a 2003 Windows Server, and one of the batch files that previously worked but no longer does after an upgrade, is a variable that I cannot figure out.

The batch file reads as such:
call "%SoftwareDir%\Utils\change.bat" "%1" "%2"
but I'll receive the following, "The system cannot find the path specified."
I know the path of the directories it is supposed to be pulling from and if I edit the batch file with the exact path such as:
call "D:\Software\Utils\change.bat" "%1" "%2"
the script will run without error.

What I'm trying to figure out is what the %SoftwareDir% refers to, and where it is set.  I thought it would be listed under the Set command, but after seeing the output from Set, I don't see anything referencing "SoftwareDir."  Anybody know where I can find what path this variable is referring to?  Thanks.

Eric
0
Comment
Question by:Nevada6372
[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
  • 3
5 Comments
 
LVL 6

Assisted Solution

by:tmwsiy
tmwsiy earned 83 total points
ID: 36545493
This is just an environment variable like any other.

For some reason this variable was previously defined somewhere and now is not getting set in shell it is being run in.

You have to remember that environment variables set within a script will go away when the cmd.exe that it was invoked with dies (IE when control is returned to you and the shell waits for another command).

Make sure you have echo on and place something like this in the batch script with the call
echo %SoftwareDir%
call "%SoftwareDir%\Utils\change.bat" "%1" "%2"

IF you know the path that SoftwareDir should be you can either just paste it in with the actual path or set it

ie
SET SoftwareDir=c:\pathtosoftware

hope this helps!

0
 
LVL 33

Accepted Solution

by:
knightEknight earned 84 total points
ID: 36545509
It was probably set on the previous system, but not on this one.  Two options - you can set this variable at the system level so it is available to the entire system, or you can just set it in the batch near the top:

@echo off
setlocal
set SoftwareDir=D:\Software

:the rest of your script here and below...
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 36545528
To set this at the system level, right-click on My Computer / Properties / Advanced system settings.  Then click on the Environment Variables button and create a new System variable called SoftwareDir with the appropriate path value.
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 36545533
... after that you will need to close and re-open your command prompt.  Then when you run the SET command you should see it, and it will work in the script.
0
 
LVL 11

Assisted Solution

by:paultomasi
paultomasi earned 83 total points
ID: 36545724
As knightEknight suggests, include the following line in your batch file prior to the CALL statement:

   set SoftwareDir=D:\Software


The following line should then work okay:

   call "%SoftwareDir%\Utils\change.bat" "%1" "%2"


Furthermore, you should consider using %~1 and %~2 instead of just %1 and %2 when including double-quotes. Like this:

   call "%SoftwareDir%\Utils\change.bat" "%~1" "%~2"

The reason for this is that should %1 or %2 already include double-quotes (possibly from the command line, user or a previous CALL), you'll need to strip these away before adding another pair otherwise you may end up with TWO double-quotes at both ends of %1 and %2.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip Migration Tip #1 – Source Server Health can be found here: http://www.experts-exchang…
Know what services you can and cannot, should and should not combine on your server.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

624 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