Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change directory then run command batch file?

Tags:

batch-file

How would you change the directory in a batch file then run the command in the new directory? I have got the batch file to change the directory, but will not run the command. It is not an exe, it is a file with -options. So basically I need to change the directory, then run a command that is saved in a string.

like image 376
dannyn382 Avatar asked Sep 11 '12 06:09

dannyn382


People also ask

How do I change the drive in a batch file?

To change to a specific drive letter while the command prompt directory is using a different drive letter than the one you need to change to, simply use the /D parameter with the CD command (e.g. CD /D <DriveLetter>: ) to change to a different drive letter before running proceeding commands.


3 Answers

Try using

pushd yourdir
filetorun -options
like image 199
Bali C Avatar answered Nov 23 '22 18:11

Bali C


I have given a sample code below to change the directory and run a command after that.

cd C:\    #Will change the directory to C:
ipconfig  #Will return IP address details(any command can be used here)
pause     #Will prevent command prompt from closing and waits for a keypress

Save this as a batch file filename.bat and you will get desired output. But make sure that the command entered is correct.

like image 32
arulmr Avatar answered Nov 23 '22 17:11

arulmr


"cd" stands for "ChangeDirectory". With "cd" command you can change the directory.

See also: http://en.wikipedia.org/wiki/Cd_(command)

Cheers

like image 44
Rikki Avatar answered Nov 23 '22 19:11

Rikki