我正在尝试执行以下操作:
Workflow spawnInParallel() {
$task1 = { "Dir C:\; pause" }
$task2 = { "Dir C:\Windows; pause" }
$task3 = { "ng build --prod; pause" }
$tasks = $task1, $task2, $task3
ForEach -Parallel ($task in $tasks) {
start powershell "& $task"
}
}
spawnInParallel
我将DOS命令封装为字符串只是因为我不知道更清洁的方式。
我不知道这是否是Workflow,Jobs或其他任务。希望保持干净简洁..使用PS 5.1。
所需的结果将是原始的,加上3个新的Powershell Windows运行命令而不是立即关闭。
使用更新的已接受答案实施
Workflow showParallel() {
param([String[]] $procs)
$tasks = @()
foreach ($proc in $procs) {
$tasks += " cmd.exe /c 'Echo Running $proc&$proc&pause' "
}
foreach -parallel ($task in $tasks) {
Start-Process powershell "-c $task"
}
}
$app1BuildCmd = "ng build --app app1 --prod --output-path $app1Root"
$app2BuildCmd = "ng build --app app2 --prod --output-path $app2Root"
$app3BuildCmd = "ng build --app app3 --prod --output-path $app3Root"
showParallel -procs @($app1BuildCmd , $app2BuildCmd , $app3BuildCmd )
答案 0 :(得分:1)
将一堆DOS命令串在一起可能很棘手,但可以完成或进一步重构......
这似乎可以做你想要的,或者至少可以用来实现你的最终结果......
Workflow showParallel()
{
$t1 = {
cmd /k echo t1 in cmd here...`&pause
}
$t2 = {
cmd /k echo t2 in cmd here...`&pause
}
$t3 = {
cmd /k echo t3 in cmd here...`&pause
}
$tasks = $t1, $t2, $t3
foreach -parallel ($task in $tasks)
{
Start-Process powershell "-noexit `"$task`""
}
}
showParallel
根据OP的请求更新
Workflow showParallel()
{
$name1 = 't1!'
$run1 = "echo $name1 in cmd here..."
$t1 = "
cmd.exe /c '$run1&pause'
"
$t2 = {
cmd /c echo t2 in cmd C here...`&pause
}
$t3 = {
cmd /k echo t3 in cmd K here...`&pause
}
$tasks = $t1, $t2, $t3
foreach -parallel ($task in $tasks)
{
$task
#Start-Process powershell "-noexit -c $task"
Start-Process powershell "-c $task"
}
}
showParallel