Solved

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

Posted on 2011-09-15
5
349 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
  • 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

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 listed in my profile here: http:…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

813 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now