Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Bios changes 5 46
Scrollbar on an excel page 4 24
Robocopy command line 6 32
How to make an ADE file by code? 11 38
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

19 Experts available now in Live!

Get 1:1 Help Now