Prober Posted January 13, 2008 Share Posted January 13, 2008 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 /SREGEDIT /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 More sharing options...
legionaire Posted January 13, 2008 Share Posted January 13, 2008 (edited) 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 January 13, 2008 by legionaire Link to comment Share on other sites More sharing options...
Yzöwl Posted January 13, 2008 Share Posted January 13, 2008 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?.ExamplesFOR %%? 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 offpushd %~dp0echo:INSTALLING:-echo:7-Zip 4.57Start "7-Zip" /wait 7z457.exe /SRegedit /s 7-zip_open.regCopy 7z.dll "%ProgramFiles%\7-zip"popd Link to comment Share on other sites More sharing options...
Prober Posted January 13, 2008 Author Share Posted January 13, 2008 (edited) 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 popdSo, 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.cmdFOR %%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.cmdCLS@echo offTITLE Installing Software Programpushd "D:\Unattended Setup"@echo Adding Variable Environment and Enabling Windows Media Player 11 Video OverlayREGEDIT /S ".\Variable_Environment.reg"REGEDIT /S ".\Enable_video_overlay.reg"@echo.@echo INSTALLING:-@echo 7-Zip 4.57@7z457.exe /SREGEDIT /S ".\7-zip_open.reg"COPY ".\7z.dll" "%ProgramFiles%\7-zip\7z.dll" Edited January 13, 2008 by Prober Link to comment Share on other sites More sharing options...
jaclaz Posted January 13, 2008 Share Posted January 13, 2008 popd is the "opposite" of pushd.In other words, it reverts the effect of pushd, see this simple example:http://www.ss64.com/nt/pushd.htmljaclaz Link to comment Share on other sites More sharing options...
Prober Posted January 13, 2008 Author Share Posted January 13, 2008 (edited) 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 January 13, 2008 by Prober Link to comment Share on other sites More sharing options...
Yzöwl Posted January 13, 2008 Share Posted January 13, 2008 Try replacing with the followingMy Install.cmd@Echo offTitle Installing Software ProgramClsPushd %~dp0Echo:Adding Variable EnvironmentRegedit /s Variable_Environment.regEcho:Echo:Enabling Windows Media Player 11 Video OverlayRegedit /s Enable_video_overlay.regEcho:Echo:Installing 7-Zip 4.57Start "7-Zip" /wait 7z457.exe /SRegedit /s 7-zip_open.regCopy 7z.dll "%ProgramFiles%\7-zip"PopdIt uses the syntax I've already provided you with earlier in this thread. Link to comment Share on other sites More sharing options...
legionaire Posted January 13, 2008 Share Posted January 13, 2008 Ok, here's what I meant:1) Instead of using "%%?:\Install.cmd" use pushd %%:call Install.cmd2) 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 More sharing options...
Prober Posted January 14, 2008 Author Share Posted January 14, 2008 (edited) 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 January 15, 2008 by Yzöwl Link to comment Share on other sites More sharing options...
Yzöwl Posted January 14, 2008 Share Posted January 14, 2008 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now