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

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.

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:-
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:-
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:-
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

Related

nircmd: I can't run another batch file with nircmd.exe?

I have wrote a batch file that i want to run another program with nircmd.exe. But the problem is i can't run it? The batch file(Matrix.bat) runs correctlyby double-click it. But when i trying to open it with nircmd.exe, it doesn't run? why?
i tried two method:
RunMethod1.bat (for runing another batch file)
SET INSTALLPATH=d:\atlantic
start %INSTALLPATH%\nircmd exec show %INSTALLPATH%\Matrix.bat
RunMethod1.bat (for runing another batch file)
SET INSTALLPATH=d:\atlantic
%INSTALLPATH%\nircmd exec show %INSTALLPATH%\Matrix.bat
The exec command in nircmd does not run batch files but executable files. Change your code to
start "" "%INSTALLPATH%\nircmd.exe" exec show "%comspec%" "%INSTALLPATH%\Matrix.bat"
Now, nircmd executes a cmd instance that will handle the batch file execution
The problem was in path of nircmd.exe. I set path of nircmd but i didn't know why it isn't work correctly? with "pushd" command i set the path of cmd into where nircmd.exe exist. and Bow!!! everything works cerrectly. Maybe a syntax problem. If everyone know that say it here.
SET INSTALLPATH=d:\atlantic
pushd %INSTALLPATH%
nircmd exec show Matrix.bat

Start Command in CMD Window

I use below command in CMD window:
start notepad.exe
Is start a short-cut for an executable in Windows like:
C:\Windows\System32\start.exe
or is it a parameter to be passed to cmd.exe?
When I use
wcsript test.vbs
wcsript refers to
C:\Windows\System32\wcsript .exe
So I want to ask does same apply for start command?
Some commands available in CMD are built directly into CMD.EXE. I believe start, like dir, is one of those commands. You won't find a separate program called dir.exe or start.exe.
You do not need to use start, simply the location of your script with the filename+extension works.
The reason you can start notepad is because it is inside the Windows folder where CMD also is.
If it's on your desktop use: C:\Users\%Username%\Desktop\test.vbs
If you have multiple files you can make a script using:
cd C:\Users\%Username%\Desktop\
test1.vbs
test2.vbs

How to Make a .bat file with arguments

For my work I have to run a string in "run".
I want to make this in a bat file but the arguments are not used but without them the program will not run.
This is the string:
"C:\Program files (x86)\MicroTouch\MT7\TwUI.exe" TwUICP.dll CPMain
Can someone help me with this problem?
You can simply put the same line of code into your bat file:
"C:\Program files (x86)\MicroTouch\MT7\TwUI.exe" TwUICP.dll CPMain
There are some options you can use. For example if you want the program to run hidden in background you can add start /b before the line. start /w will make the cmd window stay open and wait for your program to finish. You can even definde which CPU cores the program should use. For more information open the console and type start /? or check out http://ss64.com/nt/start.html.
Have the same problem, same software i think...
"C:\Program Files (x86)\MicroTouch\MT 7\TwUI.exe" twuicp.dll CPMain
Running that line through task manager -> new task will open a tool to configure touch-screen options, calibrate, etc...
Well same line doesnt work in a bat or cmd file. If i try to launch this tool through cmd.exe it doesnt work either.
The answer is always the same:
USAGE: twui <DLL name> <UI symbol name>
This works, but same line in cmd.exe dont

Scheduling automated scripts suite run from schedular

So I tried and tried but couldn't figure out this one for some reason.
how can I run a task from a desired directory instead of System32 directory where cmd.exe is.
so, when I schedule a task and try to run it ..
command prompt suppose to go to "c:\users\aaa\bbb\ccc" and then pass the argument.
Instead, It's starts at c:\Windows\System32 and fails.
Could anybody help me with this please?
I really appreciate it.
Thank you.
EDIT --
so, now I have a run.bat file with following content in it ...
C:\Users\aaa\bbb\ccc\dd (location to my testrunner.bat file)
testrunner.bat Scripts/all.suite website-address ie (command for the task I wanna perform)
net stop schedule (since window is poping up and going away way to fast, I added this to stop it (not working))
type run.bat
#echo off
cd C:\Users\aaa\bbb\ccc\dd
rem this will show all files in dir
rem is the file you're expecting listed?
dir
rem notice how you can make comments with a leading rem(ark)
#echo starting scripts\all.suite
rem you have to change this to have the full path using Windows X:\dir\dir conventions
c:\home\Scripts\all.suite website-address
#echo done running scripts\all.suite website-address
#echo shutting down
net stop schedule
So its still not clear exactly to me your goal. The reason I added the cd c:\... command is that will **C**hange **D**irectory to the path specified.
This is what you need so you can "run a task from a desired directory instead of System32".
Copy everything from the first #echo off to the last net stop and using notepad, paste it into a file, fix command names and paths website-urls, etc, then save that file to c:\temp\testrunner.bat.
Open a cmd.exe window and test that the script works. Just paste c:\temp\testrunner.bat on to cmd-line and hit enter. If that works, then made an entry in the scheduler to run c:\temp\testrunner.bat . I don't know the specifics of running a script for scheduler, so look for clues on the input screen. Is the an option to run 'now'?
If the .bat file doesn't work from the command-line, then you have to fix the file before you try running it in the scheduler. As your command Scripts/all.suite website-address is a little vague, you'll do better to post a new question asking for help to fix the .bat file and use a sample command that people will be able to use on their PCs at home.
IHTH.

How do I make a cmd script that once it is run, remains open and accepts new commands?

I want to make a cmd script that performs an action but then remains open and I can type new commands.
I have failed to find the proper terms to google as my knowledge of shell is almost zero.
thank you!
You can specify a command shell to run a specific command during start-up using the /k switch. E.g.
cmd /k C:\InitialScript.bat
The command shell would execute the C:\InitialScript.bat batch file and remain open for the user to type further commands.
If you want to create an icon for users to use then create a shortcut and use the following as the target:
%WINDIR%\System32\cmd.exe /K C:\InitialScript.bat
If you already have a command shell window open, then just use the following which will run the batch file in the context of the existing shell:
C:\InitialScript.bat

Resources