windows - 在新终端中运行命令,稍后终止

标签 windows powershell batch-file cmd

我有一个类似于下面的 start.bat:

start npx tailwindcss -i ./www/src/styles/main.css -o ./www/dist/styles/main.css --watch
start caddy run

它启动 2 个新的 cmd 提示并启动其中的进程(它们都无限期地运行)。这个 bat 文件有没有办法向它生成的 cmd 发送 kill 命令?理想情况下,我有一个命令可以杀死所有创建的“子”进程。

最佳答案

PowerShell 解决方案 - 这是可以接受的,因为这个问题的标记暗示和 icanfathom(OP)在评论(“不,PS 会很好”)- 使用 Start-ProcessStop-Process命令:

$processes = & {
  Start-Process -PassThru npx 'tailwindcss -i ./www/src/styles/main.css -o ./www/dist/styles/main.css --watch'
  Start-Process -PassThru caddy run
}

# ...

# Stop (kill) all launched processes.
$processes | Stop-Process

关于windows - 在新终端中运行命令,稍后终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71533137/

相关文章:

c# - Windows 7 将如何编程? .NET 还会是王者吗?

c++ - 如何使用 unicode 文件名打开 std::fstream(ofstream 或 ifstream)?

user-interface - Powershell - GUI 和菜单条

windows - 在 powershell 中使用不同的分隔符和引号导入 csv

.net - 获取 AzureRmResource : A parameter cannot be found that matches parameter name 'Tag'

sql-server-2005 - 如何加快 Coldfusion 中的批处理作业?

python Selenium : WinError 10053 - host is shutting connection down

ruby-on-rails - 安装 libv8 时出错 : ERROR: Failed to build gem native extension

windows - 使用从另一个目录拖放到批处理文件上不起作用

java - 在 Java 程序中在远程计算机上运行批处理文件