windows 从批处理文件在新窗口中启动进程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6306412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Start a process in a new window from a batch file
提问by Bruce
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?
我在 Windows 中编写了一个批处理文件 (.bat)。我想在新窗口中执行特定进程。我该怎么做呢?
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
...
....
回答by Anders
Use the start command:
使用启动命令:
start foo.py
or
或者
start "" "c:\path with spaces\foo.py"
回答by Mechaflash
start "title" "C:\path\to\file.exe"
开始“标题”“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 命令调用该标题。
TASKKILL /im title
TASKKILL /im 标题
回答by Ozzius
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.
杀死进程后,结果运行顺利。
回答by cr1pto
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.
下面的解决方案是在同一个窗口中调用多个文件;这个问题已经得到了回答,所以我只是增加了我的 2 美分。
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.
在其他批处理文件中,您可以调用“start”命令在单独的窗口中启动它们。
master.bat
大师.bat
call myCoolBatchFile1.bat
call myCoolBatchFile2.bat
call myCoolBatchFile3.bat
If you are using Windows Powershell, you can use the Start-Process command.
如果您使用的是 Windows Powershell,则可以使用 Start-Process 命令。
myPowershell.ps1:
我的Powershell.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
有关 start 命令及其用法以及其他脚本技术的更多信息:https: //ss64.com/nt/start.html