Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Problem with some Cmd.exe command

Featured Replies

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)


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

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

Edited by legionaire

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

  • Author

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

  • Author

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

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.

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".

  • Author

Oh thanks to Yzowl and legionaire.

I would add the popd at the end.

And a new question here.

Question removed by Moderator due to new Topic

Edited by Yzöwl

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

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.