Bruce
Bruce

Reputation: 35275

Start a process in a new window from a batch file

I have written a batch file (.bat) in windows. I want to execute a particular process in a new window. How do I do this?

Example

a.py -s 3 -l 5
b.py -k 0  -> I want to start this in a new window and let the original batch file continue 
C:\program.exe
...
....

Upvotes: 29

Views: 49858

Answers (4)

Ozzius
Ozzius

Reputation: 139

As per the requirement, we can follow up like this. As I was doing an automation work for my office purpose. So I need to create a process for a certain time, & after that I have to kill the service/ process. So What I did, For start a process:

**`start "API" C:\Python27\python.exe`**

Then I tried with my all other works & tasks. After that I need to kill that process. So That I did,

**`taskkill /F /IM python.exe`**

After killing the process, outcome ran smoothly.

Upvotes: 0

cr1pto
cr1pto

Reputation: 549

The solutions below are for calling multiple files in the same window; this question has been answered already so I am just adding my 2 cents.

If you are working with a master batch file that calls multiple other batch files, you would use the "call" command. These aren't processes, though.

Within the other batch files you can call the "start" command to start them in separate windows.

master.bat

call myCoolBatchFile1.bat
call myCoolBatchFile2.bat
call myCoolBatchFile3.bat

If you are using Windows Powershell, you can use the Start-Process command.

myPowershell.ps1:

#silent install java from java exe. 
$javaLogLocation = "[my log path here]"
$javaFileName = "[javaInstaller file name here].exe"
$process = "$javaFileName"
$args = "/lang=1033 /s /L $javaLogLocation"
Start-Process $process -ArgumentList $args -Wait

For more info on the start command and its usages, as well as other scripting tech: https://ss64.com/nt/start.html

Upvotes: 1

Anthony Miller
Anthony Miller

Reputation: 15920

start "title" "C:\path\to\file.exe"

I would highly recommend inserting a title so that you can call that title later via the TASKKILL command if needed.

TASKKILL /im title

Upvotes: 9

Anders
Anders

Reputation: 101656

Use the start command:

start foo.py

or

start "" "c:\path with spaces\foo.py"

Upvotes: 42

Related Questions