Start a process in a new window from a batch file

久未见 提交于 2021-02-07 04:46:05

问题


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

回答1:


Use the start command:

start foo.py

or

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



回答2:


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




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/6306412/start-a-process-in-a-new-window-from-a-batch-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!