0
Batch. How can I start two command prompts in batch and change the directory to the second command prompt only?
I am trying to open two command prompts in batch at the same time I want to change the directory on both of them each to a different directory. how can I do that in Batch? I hope I am asking in the right place?
11 ответов
+ 2
If you mean MSDOS / Windows batch language, depending on your kernel you may be looking for a parameter to COMMAND.COM or CMD.EXE
COMMAND shell
COMMAND /? or CMD /?
There, you'll see /C and /K. One executes a command and exits (I think it's /C). The other executes and stays running.
There may be parameters to set the "working directory" on start.
START
And in most recent Windows, you can also use the "start" command , e.g.:
start /? -- should print to console or pop up a window with parameters
...to preload certain things before executing a binary, like the "working directory".
You can also create PIFs (program information files) and launch those with preconfigured parameters (working directory and start directory).
BATCH JOB start
If you want to just start a batch job, the actual command I think you're looking for is "CD".
@ECHO OFF
CD C:\place\to\land
REM end of script
Start that with /K and I believe the command prompt will land at that dir.
+ 2
What's the output of this:
C:\>test.bat "C:\WINDOWS"
test.bat:
@ECHO OFF
CD "%1"
CD
+ 1
Look at this answer. The /D to "also change the drive" is extra (possibly helpful) information to the basic function: use a batch file to change the working directory:
https://stackoverflow.com/questions/5138507/how-to-change-current-working-directory-using-a-batch-file
This one mentions using pushd:
https://stackoverflow.com/questions/12363620/how-to-change-directory-then-run-command-batch-file
+ 1
I believe "start" takes the context of Windows, not the command shell (I remember this as a source of confusion for people mixing these).
There's a /D parameter for Start:
https://stackoverflow.com/a/14842307
Just shotgunning it, you may also want to put 'cd' at the top of vsdevcmd.bat
+ 1
vsdevcmd.bat:
start /D "path\to\use" secondshell.bat
or send it as a parameter to secondshell:
secondshell.bat "path\to\use"
secondshell.bat:
cd "%1"
+ 1
Sorry for the delay; I couldn't find the alerts for this, thought it was gone, then searched once more just in case.
On a Windows XP system, I created a file:
C:\>notepad test.bat
@echo off
CD C:\windows
CD
then ran it:
C:\>test.bat
C:\WINDOWS (output)
Then I commented line 2:
@ECHO OFF
REM CD C:\windows
CD
and ran start /D ... :
C:\>start /D "C:\windows" c:\test.bat
<new window>
C:\windows (output)
(blank line)
C:\windows>_ (prompt)
Then I chained batch jobs (I did not test CALL):
test.bat:
@ECHO OFF
test2.bat
test2.bat:
@echo off
cd c:\windows\system32
C:\>test.bat
C:\WINDOWS\system32>_ (prompt)
In each case the working directory was changed inside the batchjob context and remained set outside of it.
I'm perplexed that this isn't working for you, but I hope this answer catches something I missed.
0
Thanks kirk this is what I have
cd C:/
cd program files (x86)\Microsoft visual studio 12.0\common7\tools
start vsdevcmd.bat
this works and runs the developer command prompt but if I want to change the directory in the developer command prompt which i run in "vsdevcmd" it will not change. I see the regular cmd change
0
still having the same issue even with the /D. the directory only changes on the first CMD but I cannt change the directry on the second one
0
Kirk my code is actually running the start. start is not my issue. my issue is when I want to write to the second command prompt that vsdevcmd.bat will run
0
I tried it but still not changing directory on the second command prompt
0
I dont understand do you want me to jsut type that code and run it?