[英]Powershell: Script not running from command line but runs from ISE?
[英]Simple PowerShell script refuses to write file when running from command line but works fine in ISE
因此,我有一個非常簡單的PowerShell腳本,用於在構建過程中更新版本號。
$InputFile = 'D:\BuildAgent\work\c9716e2651305a2e\web\WEB-INF\classes\version.properties'
$OutputFile = $InputFile
Write-Host $('Updating "' + $OutputFile + '" to reflect version "2.10.0.51"')
(Get-Content $InputFile) |
Foreach-Object {
$_ -replace 'version.release\s*:.*','version.release: 2.10.0.51'
} |
Out-File $OutputFile
它在ISE中可以正常工作,但是當我從命令行運行時
powershell.exe-命令-<powershell2447437064467034590.ps1
要么
powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass-命令-<powershell2447437064467034590.ps1
盡管所有這些都將文件清空。 如何通過ISE而不是通過命令行正常工作?
“默認情況下,Windows Powershell不會從當前位置加載命令。如果您信任此命令,請鍵入“。\\ test.ps1”
-Windows Powershell
powershell.exe .\powershell2447437064467034590.ps1
我用Powershell命令提示符和經典命令提示符進行了測試
欲獲得更多信息
從增強的腳本或命令Powershell 3.0運行
Update-Help
Get-help about_Command_Precedence
我想到了。 我使用了文件中的標簽來漂亮地打印和格式化文本。 顯然,這打破了它。 如果我將其復制並粘貼到ISE中,它將以靜默方式將所有選項卡轉換為空格,這就是它在那里起作用的原因。 令人驚訝的是,令牌生成器沒有將所有空格都相同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.