Jump to content

Problem with some Cmd.exe command


Recommended Posts

I have a question here.

I have created a command file called Runinstall.cmd in C:\

I put these lines in Runinstall.cmd to call another command file (Install.cmd) in different location:

------------------

FOR %%U IN (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%U:\Install.cmd SET DRV=%%U:

%DRV%\Install.cmd

------------------

Well, the Runinstall.cmd can call the Install.cmd in different location , but some silly things occur.

I use Install.cmd to install software programmes.

As the installers or items are in the same directory as the Install.cmd, I can just specify the file names without specifying the path of the files in the Install.cmd. Below are the examples (see red lines):

@echo off

@echo INSTALLING:-

@echo 7-Zip 4.57

@7z457.exe /S

REGEDIT /S ".\7-zip_open.reg"

COPY ".\7z.dll" "%ProgramFiles%\7-zip\7z.dll"

When I run Install.cmd, it works and does everything very well without any problems.

But when I use Runinstall.cmd to call Install.cmd, it stated that it can't find the 7z457.exe.

- Unless the 7z457.exe exists in where the Runinstall.cmd located, I found out.

Now I know what had happened. When Runinstall.cmd calls Install.cmd, the commands in Install.cmd has become the commands of Runinstall.cmd. I mean the commands of Install.cmd are run by Runinstall.cmd.

In this case, as those installers are not in where Runinstall.cmd located, Runinstall.cmd says it cannot find the files.

--- It is just like I move the Install.cmd to another location, that is, not in the same folder with the installers, And when I run it, It says it can't find the files.

Is anyone here able to solve this problem without specifying the path of the installers?

(ie. change 7z457.exe /S to D:\Unattended Setup\7z457.exe /S)

Link to comment
Share on other sites


As well as using the pushd command, also bear in ming that you tell us that your calling another script when in actual fact you would use the call command to call it and you are not. If that is the entire content of the Runinstall.cmd you'd be fine, but I'm guessing that it's not.

Also what are all the @ symbols used for?.

Examples

FOR %%? IN (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO (
IF EXIST %%?:\Install.cmd CALL %%?:\Install.cmd)

@echo off
pushd %~dp0
echo:INSTALLING:-
echo:7-Zip 4.57
Start "7-Zip" /wait 7z457.exe /S
Regedit /s 7-zip_open.reg
Copy 7z.dll "%ProgramFiles%\7-zip"
popd

Link to comment
Share on other sites

I don't understand what legionaire is trying to say:

Simply use cd to change into the dir of install.cmd before you call it.

And what do the non-subpath in the next sentence you mean?

pushd is even better as you can specify a non-subpath as well.

At first I don't understand what is pushd and how to use it, so do popd

So, I add the command pushd %~dp0 above "echo:INSTALLING:-" as what Yzöwl showed.

Then I google for it and now I know how to use it:

pushd <specify the path>

A bit confusing as you all did not explain well. But, anyway,

Thanks a lot guys!!!

And I would also like to have answers for my questions above, please, and what is popd. I haven't google for it.

My Runinstall.cmd

FOR %%U IN (C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST "%%U:\Unattended Setup\Install.cmd" CALL "%%U:\Unattended Setup\Install.cmd"

My Install.cmd

CLS
@echo off
TITLE Installing Software Program

pushd "D:\Unattended Setup"
@echo Adding Variable Environment and Enabling Windows Media Player 11 Video Overlay
REGEDIT /S ".\Variable_Environment.reg"
REGEDIT /S ".\Enable_video_overlay.reg"
@echo.

@echo INSTALLING:-
@echo 7-Zip 4.57
@7z457.exe /S
REGEDIT /S ".\7-zip_open.reg"
COPY ".\7z.dll" "%ProgramFiles%\7-zip\7z.dll"

Edited by Prober
Link to comment
Share on other sites

Wow... Just a few minute later then another one come to post here...

Thank you jaclaz!!!

QUOTE Any answer, please...

------------------------------------------------------------------------------------------

I don't understand what legionaire is trying to say:

Simply use cd to change into the dir of install.cmd before you call it.

And what do the non-subpath in the next sentence you mean?

pushd is even better as you can specify a non-subpath as well.

------------------------------------------------------------------------------------------

Edited by Prober
Link to comment
Share on other sites

Try replacing with the following

My Install.cmd

@Echo off
Title Installing Software Program
Cls
Pushd %~dp0

Echo:Adding Variable Environment
Regedit /s Variable_Environment.reg

Echo:
Echo:Enabling Windows Media Player 11 Video Overlay
Regedit /s Enable_video_overlay.reg

Echo:
Echo:Installing 7-Zip 4.57
Start "7-Zip" /wait 7z457.exe /S
Regedit /s 7-zip_open.reg
Copy 7z.dll "%ProgramFiles%\7-zip"

Popd

It uses the syntax I've already provided you with earlier in this thread.

Link to comment
Share on other sites

Ok, here's what I meant:

1) Instead of using "%%?:\Install.cmd" use

pushd %%:
call Install.cmd

2) Using cd you can only navigate to subpaths. E.g. if you'r in C:\Windows, cd D:\Something won't work. However, pushd D:\Something will work. That's what I meant by "non-subpath".

Link to comment
Share on other sites

Using cd you can only navigate to subpaths. E.g. if you'r in C:\Windows, cd D:\Something won't work.
That's because you're not using the command correctly, in that case you should be using:
cd /d D:\Something

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...