Navigate to a specified path in cmd file - cmd

Now I am currently in C:\WINDOWS\system32>
I need to mention it in the cmd file
How can I navigate to a specific path in cmd file.
Please provide the lines.
#echo off
setlocal
call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"
cd "C:\hadoop-2.6.0-src"
mvn package -Pdist,native-win,docs -DskipTests -Dtar
pause
popd
This is my cmd file.The mvn command is not getting executed in the specified path. two separate command prompts is getting opened but it is not running and get closed immediately
Thanks in advance.

PUSHD Change the current directory/folder and store the previous folder/path for use by the POPD command
#echo off
setlocal
pushd "C:\hadoop-2.6.0-src"
cd
pause
call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"
cd
pause
popd
Additional cd commands (without parameters) should display the current drive and directory.
Read more

Related

How can I create a windows 10 script which runs a command under specified path?

I created a npmruns.bat file with a content:
C:\myfolder>npm run s
I wanted to create a script file which run a command: npm run s under specified location: C:\myfolder , but it doesn't work. I run it by double click (I have an admin rights).
I tried to create a script which can be executed from any location (other than C:\myfolder).
pushd and cd /d will be the options for this:
#echo off
pushd "C:\myfolder"
call npm.cmd run s
popd
This will push to the path of the batch-file as the working directory, popd is not required if you do not need to go back to the starting working directory, which as admin, will be "%systemroot%\system32"
Alternatively you can run:
cd /d "c:\myfolder"

Visual studio 2017 Developer Command Prompt switches current directory

I am getting weird behavior of "Developer Command Prompt for VS 2017" command line tool. Normally in previous versions of visual studio this script (VsDevCmd.bat) was not messing current directory from where you run it. Now it seems to change it. One simple workflow would be just to start the shortcut "Developer Command Prompt for VS 2017" and it doesn't honor the "Start in" directory:
By any chance anyone seen this issue? It really bugs me because I used to have a shortcut with it and start CMD in my source directory, use TFS/msbuild commands afterwards.
You can set the VSCMD_START_DIR environment variable to have vsdevcmd.bat change to that directory when it finishes. Otherwise it will check if you have a %USERPROFILE%\source directory and change to that (which is what you see).
You can change the "Target" for the "Developer Command Prompt for VS 2017" to something like the following to have change to a particular directory:
%comspec% /k "set VSCMD_START_DIR=C:\temp && "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat""
Note that the path to vsdevcmd.bat needs to be put in an additional set of double quotes.
Alternatively, rename or remove the %USERPROFILE%\source directory (Note that this seems to be some kind of new "standard" directory for sources), that will make vsdevcmd.bat honor the "Start In"-value (i.e. "current directory").
:: Some rocket scientist in Redmond made the VS15 VsDevCmd.bat change the cwd; the pushd/popd fixes that.
pushd %CD%
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools\VsDevCmd.bat"
popd
"C:\Program Files (x86)\CruiseControl.NET\server\ccnet.exe" %*
vsdevcmd_end.bat, REM out the line:
cd /d "%USERPROFILE%\Source"
#REM Set the current directory that users will be set after the script completes
#REM in the following order:
#REM 1. [VSCMD_START_DIR] will be used if specified in the user environment
#REM 2. [USERPROFILE]\source if it exists
#REM 3. current directory
if "%VSCMD_START_DIR%" NEQ "" (
cd /d "%VSCMD_START_DIR%"
) else (
if EXIST "%USERPROFILE%\Source" (
cd /d "%USERPROFILE%\Source"
)
)
If I see your quastion in right way that I'm used to work with EntityFramework Core with the help of CMD or PowerShell. For this you should right-click In the Solution Explorer panel then in the context menu, click Open Folder in File Explorer. In the address bar of the file explorer type cmd or powershell, you will start the command line from the project folder.

TortoiseSVN client-side hooks in project properties (delete cache files)

I have several php-projects under SVN control. I want to delete compiled php-template files after update on the client side; these files are located in ./tmp/smarty/compile folder. So using windows command line I can do this using
del /Q path_to_my_project\tmp\smarty\compile
If I run this command in cmd.exe all files are successfully deleted.
using projects properties tsvn:postupdatehook I should use %REPOROOT% placeholder for project path. so my command becomes:
del /Q %REPOROOT%\tmp\smarty\compile
del is the cmd.exe command, so I need to run cmd.exe first and then run desired command. so finally my hook command looks like:
cmd.exe /c del /Q %REPOROOT%\tmp\smarty\compile
when I run this using Win+R (with reporoot changed to full path) it works fine too.
Then I put this line to SVN properties (I should replace \ slashes to /, overwise SNV returns http-path to repository, not local path), and try to update project. TortoiseSVN asks me if I want to run hook:
cmd.exe /c del /Q D:\_projects\webCakePHP\.....\tmp\smarty\compile
So here reporoot is successfully translated to correct working copy path.
Everything looks fine, but when I run this hook, it successfully deletes files in tmp\smarty\compile but it also deletes all files from working copy dir.
the question is, what am I doing wrong, and how to delete files after update right way.
I've tried to put quotes some ways but it doesn't delete enything at all or says that there is no such directory.
thanks
as an alternate solution to my question, i've created .bat file in %REPOROOT%/bin folder, which deletes files:
pushd %~dp0..\tmp\smarty\compile
del /Q *
popd
and my hook cmd string is %REPOROOT%/bin/clearCache.bat.
this is not exact answer to my question because it requires bat-file creation and isn't one-line hook.

Batch can't find .exe files inside C:\Program Files (x86)

This is the code i'm using:
cd "D:\HigherFolder\FolderX"
start executable1.exe
cd "C:\Program Files (x86)\FolderY\"
start executable2.exe
cd "C:\Program Files (x86)\FolderZ\bin\"
start executable3.exe
exit
I want to start one .exe after the another, or at the same time, but this does not work with executables 2 and 3; command prompt says it can't find the files and that i need to certify that their names are correct (which i did, multiple times).
Change it to cd /d on command #2. (You can add it to commands 1 & 3 also for safety.) Your code operates on two separate drives, but CD only changes directories on the current drive without the /d switch.
cd /d "D:\HigherFolder\FolderX"
start executable1.exe
cd /d "C:\Program Files (x86)\FolderY\"
start executable2.exe
cd /d "C:\Program Files (x86)\FolderZ\bin\"
start executable3.exe
exit
Run cd /? from a command prompt for more info. An excerpt shows:
Use the /D switch to change current drive in addition to changing current
directory for a drive.

Open cmd, change directory and execute command

I'm trying to write a simple batch file to initialize some tools I need on windows startup.
This is what I've at the moment:
#echo off
start /d "C:\Program Files\Sublime Text 3" sublime_text.exe
start cmd.exe /k cd /d "D:xampp/htdocs/webshop"
What I'd like to do is to execute the command compass watch once the directory has changed.
I tried start cmd.exe /k cd /d "D:xampp/htdocs/webshop" /k "compass watch" but it refers to the cd command then and thus throws me an error message (The system cannot find the path specified).
Any suggestions?
EDIT
To clarify what I need:
Open console
cd to the relevant directory
Execute the command compass watch (in that directory)
I normally do this by manually typing in the commands into the console as listed above. What I'd like to have is a simple .bat file that does exactly that with just one click.
You state in the comments that you don't need a separate interpreter. In which case I believe you can do it like this:
#echo off
start /d "C:\Program Files\Sublime Text 3" sublime_text.exe
start /d D:\xampp\htdocs\webshop compass watch
This an example to open Firefox.exe.So you should do like this, for your programs
#echo off
echo Try to open Firefox ....
CD /D %programfiles%\Mozilla Firefox\ & Start Firefox.exe
Pause
Try This :
#echo off
CD /D %programfiles%\Sublime Text 3 & Start sublime_text.exe
CD /D D:\xampp/htdocs/webshop & Start compass watch
Pause
You have to use Backslash in your path "\".
Did you try :
#echo off
"C:\Program Files\Sublime Text 3\sublime_text.exe"
cd /d "D:\xampp\htdocs\webshop"
"D:\xampp\htdocs\webshop\compass watch.exe"
This should work to launch the exe, and change folder, then use cmd /k to execute the compass command and leave the console open.
#echo off
start "" /d "C:\Program Files\Sublime Text 3" sublime_text.exe
cd /d "D:xampp/htdocs/webshop"
cmd.exe /k "compass watch"

Resources