Currently I want to run a batch file that fires the command git log and show me that log.
After that I need to be able to commit and view the status so this prompt may not disappear after a key press.
I've searched the net and the only answer people have is pause which close the prompt after a keypress.
Does anyone have the solution for me? Currently I made a shortcut to cmd.exe and made the target my folder, but I want to execute some commands also.
Thanks in advance.
This (below) tested OK in Windows 7. To exit the window it creates, type "exit" when done.
start cmd /K "cd \[the-target-folder] && git log"
Where:
[the-target-folder] you replace with your target folder
Note:
&& lets you run two commands on one line
/K is a parameter to the cmd shell program which which carries out the command specified by string and remains.
Related
first of all, I knew this question is duplicated but I'm new to bat file and I don't know how to develop this structure.
I want a bat file that works with windows task schedule at a specific time automatically.
I manually use this command in cmd
php\php.exe -f processmaker workspace-backup workflow
then I press enter in cmd to run this command
after that
I manually use this command in cmd
SET PATH=C:\Program Files\MySQL\MySQL server 5.6\bin
then I press enter in cmd again...
ok I want a solution to pressing "ENTER KEY" automatically between these commands.
Can you please help me?
If you edit a text file and name it, say mytask.bat
All the lines in it are executed as if in the command line, so try it, it should work.
I have a problem in my jenkins job and I isolated into one command. So I created another separate job to try to fix it.
So in this job, called "teste" I only have one single command:
start cmd /k call "C:\Program Files\myDir\myBat.bat"
This opens a separate cmd window running my bat file, which should keep running "forever".
But the problem is when I do it, my jenkins job keeps stuck into a "exit 0" operation that I have no idea from where it came from.
Thats the console:
[EnvInject] - Loading node environment variables.
Building remotely on Machine01 in workspace C:\workspace\teste
[teste] $ cmd /c call C:\...dir\jenkins.bat
C:\workspace\teste>start cmd /k call "C:\Program Files\myDir\myBat.bat"
C:\workspace\teste>exit 0
Then it keep stuck at that point.
Example of myBat.bat content:
echo hi
pause
There's any way to make this call in another window without waiting for its finish?
I solve my problem changing the way I was calling my other .bat, calling it through powershell. But since I was from a bat file, I used the command to send a powershell command, calling my other bat file.
Also, I've added another line changing the jenkins BUILD_ID to a fake one, so it doesn't kill it.
So I changed from this line:
start cmd /k call "C:\Program Files\myDir\myBat.bat"
To this :
set BUILD_ID=dontKillMe
powershell -Command "Start-Process 'C:\Program Files\myDir\myBat.bat'"
I hope it helps someone someday.
I want to have a batch file(must be placed on desktop) which does the following;
opens cmd
navigates to a directory, e.g. C:\activiti-5.9\setup
runs a command within the directory, e.g. ant demo.start (this command runs the activiti server)
I tried the following to reach to the directory but how to run command, "ant demo.start"?
START cmd.exe /k "cd C:\activiti-5.9\setup"
Thank you for the help.
EDIT:
Referring to zb226's answer below: One more question if you can answer me is how to make that cmd to be run as administrator? will the following work?
START cmd /K "runas /user:administrator & cd C:\activiti-5.9\setup & ant demo.start"
Chain arbitrary commands using & like this:
command1 & command2 & command3 & ...
Thus, in your particular case, put this line in a batch file on your desktop:
START cmd.exe /k "cd C:\activiti-5.9\setup & ant demo.start"
You can also use && to chain commands, albeit this will perform error checking and the execution chain will break if one of the commands fails. The behaviour is detailed here.
Edit: Intrigued by #James K's comment "You CAN chain the commands, but they will have no effect", I tested some more and to my surprise discovered, that the program I was starting in my original test - firefox.exe - while not existing in a directory in the PATH environment variable, is actually executable anywhere on my system (which really made me wonder - see bottom of answer for explanation). So in fact executing...
START cmd.exe /k "cd C:\progra~1\mozill~1 && firefox"
...didn't prove the solution was working. So I chose another program (nLite) after making sure that it was not executable anywhere on my system:
START cmd.exe /k "cd C:\progra~1\nlite && nlite"
And that works just as my original answer already suggested. A Windows version is not given in the question, but I'm using Windows XP, btw.
If anybody is interested why firefox.exe, while not being in PATH, is executable anywhere on my system - and very probably on yours as well - this is due to a registry key where applications can be registered to be available everywhere. See this SU answer for details.
For me, the following is working and running activiti server as well as opening the explorer in browser (with the help of zb226's answer and comment);
START "runas /user:administrator" cmd /K "cd C:\activiti-5.9\setup & ant demo.start"
START /wait localhost:8080/activiti-explorer
This question is 5 years old. I wonder why still nobody has found the /d switch to set the working folder:
start /d "c:\activiti-5.9\setup" cmd /k ant demo.start
CMD.EXE will not execute internal commands contained inside the string. Only actual files can be launched with that string.
You will need to actually call a batch file to do what you want.
BAT1.bat
start cmd.exe /k bat2.bat
BAT2.bat
cd C:\activiti-5.9\setup
ant demo.start
You may want to create a folder called BAT, and add it's location to your path.
So if you create C:\BAT, add C:\BAT\; to the path. The path is located at:
click -> Start -> right-click Computer -> Properties ->
click -> Avanced System Settings -> Environment Variables
select -> Path (From either list. User Variables are specific to
your profile, System Variables are, duh, system-wide.)
Click -> Edit
Press the -> the [END] or [HOME] key.
Type -> C:\BAT\;
Click -> OK -> OK
Now place all your batch files in C:\BAT and they will be found, regardless of the current directory.
Mine DID execute commands in order. Here's my version of what I was using it for:
START cmd.exe /k "U: & cd U:\Design_stuff\new_lcso_website_2017 & python -m http.server"
I needed to
Change to my U drive
CD to a specific folder containing a website I'm redesigning
Execute python with the http server module (to display the contents in my browser).
If those commands are out of order, it would not display the correct files. I initially forgot to change to U: and, running the batch file on my Desktop, it created a web page in my browser at http://localhost:8000 showing me the contents of my Desktop instead of the folder I wanted.
You Can Also Check It:
cmd /c cd /d C:\activiti-5.9\setup & ant demo.start
This is sort of a follow-up to my question earlier (link).
To test things out I made this simple batch file to ensure the Task Scheduler was properly executing the batch file:
cd "C:\Users\user\Desktop"
echo. 2>test.txt
So after the test.txt document is created on the desktop, the batch file should end but it continues to run:
Is there a way, either at the end of the batch file or a setting in the Task's Properties, to ensure that the cmd process quits?
Thanks!
I ran into the exact same problem. However, I felt duped when I read what Trevor778 wrote in this post:
I had the same problem - the task worked but the status kept showing Running. One simple thing to try is click on the Task Scheduler Library in the left column. Click Action/Refresh. Presto. Status changed to Ready. That's all it was for me, the task ran fine, just the status didn't update. Hope this helps.
ref: https://social.technet.microsoft.com/Forums/en-US/2f6dc29c-3b8b-45f5-a2a7-53e076acc062/task-scheduler-scheduler-status-is-being-running-always?forum=winservergen
you can add "exit" to last line of your script
cd "C:\Users\user\Desktop"
echo. 2>test.txt
exit
Running TASKKILL /F /IM cmd.exe will kill all cmd.exe processes whether it was the one that spawned this batch file or not. That's probably not desirable behavior. :-)
Judging by your last question, I'm guessing you're still running your task with cmd.exe /k, which will keep that window open indefinitely. For an unattended task, cmd.exe /c is a better choice. When the batch file finishes, the process should end.
Same here on Windows 7.
Putting all batch files in a directory in the user User specific path who runs the task
run programm = " cmd.exe " (without a path)
Your extras, mine where = " /c "C:\Users[username]\whatever\your_batchfile.bat" >> log.txt" "
" >> log.txt " so that i can see the output of the batch...
start in = " C:\Users[username]\whatever "
I also checked the "run with highest privilges" box
after that everything worked fine :)
Use following
exit /B
you may find more information in windows console area then type:exit/?
I know it's an old question, but I personally found that if I let a pause at the end of the bat file, it would keep the status as "Running".
I usually leave a pause at the end to help with debugging, but I found when I removed it, the task scheduler finally recognised it as having exited. It didn't help if I just refreshed it.
The solution I found was to add this line at the very end of the batch file:
TASKKILL /F /IM cmd.exe
Now after the batch file task runs and completes, it is no longer in the All Running Tasks list and the status goes back to 'Ready' instead of staying at 'Running'.
Warning:
That command will kill all running command processor instances so it may be potentially harmful!
I have creted a batch file that I want to run the SetupCodeGroup.exe
When I double click the batch file it doesnt run the exe file. A command prompt opens up but it doesnt run the file. Can someone tell what I missed or what I am missing
C:\Users\raw008\Desktop\Critcare\SetupCodeGroup.exe
type pause on the next line and check whether this executable comes on the command prompt .
try
start C:\Users\raw008\Desktop\Critcare\SetupCodeGroup.exe
moreover
start /d "path_to_file_directory" program.exe
is the complete line to execute program and console will not wait to program to exit .
I wonder if this exe requires administrative privileges. Try right-clicking the batch file and running it as administrator.
#echo off
start C:\Users\raw008\Desktop\Critcare\SetupCodeGroup.exe
echo Done
pause
try that if that dose not work then your computers privleges are messed up, i ran into the same problem on my cousins computer.