1

I am making a set of batch files made to force restart games when they freeze and won't start back up again.

So I need a batch file that opens cmd.exe, runs the two commands:

taskkill /F example.exe` 

and

start example.exe

and lets cmd stay open. Every time I try these two commands cmd is just open for a second and closes saying that no command was made, or the commands aren't able to be used even though they work when I type them into cmd directly.

1
  • I found out that I was encoding my batch files as unicode instead of ANSI but I wouldn't have known how to do these commands anyways if I didn't post this question May 27, 2016 at 16:13

2 Answers 2

4

I need a batch file that opens cmd, runs two commands, and keeps cmd open

taskkill /F example.exe

This is an invalid command. You need to use:

taskkill /F /IM example.exe
  • /IM image name. The image name of the process to be terminated. Wildcard '*' can be used to specify all image names.

Use the following batch file (test.cmd):

@echo off
setlocal
taskkill /F /IM example.exe
start example.exe
endlocal

To run it and keep the cmd shell open use the following command:

cmd /k test
  • /K Run Command and then return to the CMD prompt. This is useful for testing, to examine variables

Further Reading

  • An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
  • cmd - Start a new CMD shell and (optionally) run a command/executable program.
  • start - Start a program, command or batch script (opens in a new window).
  • taskkill - End one or more processes (by process id or image name).
0

You can also use pause at the end to leave it open 'till you hit a button.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .