正如标题所暗示的,当我尝试where python 从 PowerShell 中执行操作时,它什么也没有返回。没有错误或其他什么...它只是转到一个新行(就像我按“Enter”键一样)
另一方面,CMD Prompt 成功返回以下内容:
C:\Users\User>where python
C:\Users\User\AppData\Local\Programs\Python\Python38\python.exe
C:\Users\user\AppData\Local\Microsoft\WindowsApps\python.exe
Run Code Online (Sandbox Code Playgroud)
python --version成功返回 pwsh 和 cmd中的版本。有人能弄清楚如何where在 powershell 中修复吗?
我在脚本中使用格式运算符,示例如下:
$current = 1
$total = 1250
$userCN = "contoso.com/CONTOSO/Users/Adam Smith"
"{0, -35}: {1}" -f "SUCCESS: Updated user $current/$total", $userCN
Run Code Online (Sandbox Code Playgroud)
这 expectedly 显示以下输出:
SUCCESS: Updated user 1/1250 : contoso.com/CONTOSO/Users/Adam Smith
格式运算符用于将目标输出文本保持在原位,当前/总运行数字在 1-99999 之间变化。如果没有格式运算符,我可以像这样突出显示成功行:
Write-Host -BackgroundColor Black -ForegroundColor Green "SUCCESS: Updated user $current/$total: $userCN"
但问题是如何将高亮颜色与格式运算符结合使用?只有-f参数,它不允许颜色参数,因为它Write-Host与最初的不同。