Fra*_*roe 5 powershell wait visual-studio-code powershell-core
在 PowerShell Core 中,像这样生成 VS Code,以启动差异/合并:
Start-Process -FilePath "$([System.Environment]::GetEnvironmentVariable('LOCALAPPDATA'))\\Programs\\Microsoft VS Code\\code.exe" -Wait -ArgumentList "-n --diff $FullFileNameSrcFrom $FullFileNameSrcTo"
Run Code Online (Sandbox Code Playgroud)
有效,但它不会等待。我认为这是因为 code.exe 启动子进程。如果是这种情况,我可以使用-Passthru
并执行类似的操作:
Get-Process *some criteria here* | ... and check if the children processes are finished
Run Code Online (Sandbox Code Playgroud)
但是:标准是什么?
我曾经procexp
试图找出它,但没有成功。
如何识别代码生成的进程?
也许有更简单的方法?
我使用 git 和 VS Code 作为默认提交编辑器,显然 git 会等待 VS Code 终止后再继续 - 所以“他们”找到了一种方法来做到这一点。这给我/你一个提示吗?
Start-Process -Wait
还将等待子进程(来源):
使用Wait参数时,
Start-Process
等待进程树(进程及其所有子进程)退出,然后再返回控制权。这与 cmdlet 的行为不同Wait-Process
,后者仅等待指定进程退出。
我不知道为什么,但等待并不适用于所有进程。它甚至不适用于calc.exe
,但它确实适用于某些进程。
有一个解决方法可以解决您的 VS Code 问题。它本身支持等待选项:
-w
或--wait
等待文件关闭后再返回。
你可以像这样进行差异/合并,实际上Start-Process
会在哪里等待:
Start-Process code -ArgumentList "-n -d -w .\test1.txt .\test2.txt" -Wait
Run Code Online (Sandbox Code Playgroud)
你甚至不需要Start-Process
。这也将等待:
code -n -d -w .\test1.txt .\test2.txt
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
333 次 |
最近记录: |