Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create a batch file to execute command in Cmder?

I wanna create a batch file that launch Cmder and then execute some commands inside the Cmder. I know how to launch Cmder using a batch file but don't know, how to write/execute a command in Cmder using batch file.

I tries this...

@echo off

cd "C:\Program Files\cmder"
start Cmder.exe

cd "D:\Path"

Above code launches the Cmder.exe but doen't execute cd "D:\Path" inside Cmder.

like image 365
user15557745 Avatar asked Jan 26 '26 19:01

user15557745


1 Answers

You asked how to improve / fix

@echo off
cd "C:\Program Files\cmder"
start Cmder.exe
cd "D:\Path"

There are a few issues that could be better addressed in different ways. but as they appear not to be your real Issue I will simply suggest an alternative way to invoke cmder could be:-

@echo off
start "Cmder" "C:\Program Files\cmder.exe" /START "D:\Path"

I dont have a D drive so accept here my Path is e:\Path and the above command would result in the desired action, like so:-

enter image description here

In comments you explained that was not the intent but to run a cmd within cmder that would start first by changing the start directory.

What users need to acknowledge is that cmder is a very lightweight configuration wrapper around ConEmu and it is there that commands are processed as defaults or "Tasks"

So the request is to start up default Cmder and automatically change to e:\path where I can run further commands. One way to achieve this:-

enter image description here

Is to add my own MyAutoRun Task so I can invoke as

start "Cmder" "C:\Program Files\cmder.exe" /TASK MyAutoRun

Which is stored as a ConEmu Task like this:-

enter image description here

The full but limited range of Cmder arguments can be found at https://github.com/cmderdev/cmder#cmderexe-command-line-arguments

For configuring ConEmu tasks you need to see https://conemu.github.io/en/Tasks.html

like image 111
K J Avatar answered Jan 29 '26 08:01

K J