返回列表 发帖

[技术讨论] powershell 脚本 改成批处理,哪个方式比较好?

@powershell -c "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" & pause & exitCOPY
@findstr /v "^@f.*&" "%~f0" | powershell -& goto:eofCOPY

cmd的管道容易炸
@findstr /v "^@f.*&" "%~f0" | powershell -& pause&exit
$s=@'
1
2
3
4
'@
Write-Host $s
Get-DateCOPY

TOP

下面三个语句,选一个放在PS1脚本首行,对原脚本不会有影响
后缀改为BAT,则可将PS1无缝转换为BAT
#&cls&@Powershell "& {[ScriptBlock]::Create("'#' + (gc '%~f0' -raw)").Invoke()}" & pause & exit
#&cls&@Powershell "& {[ScriptBlock]::Create("'#' + ([io.file]::ReadAllText('%~f0',[text.encoding]::Default))").Invoke()}" & pause & exit
#&cls&@powershell -c "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" & pause&exitCOPY
QQ 33892006

TOP

谢谢。。。。。。。。。。。。。。。。

TOP

返回列表