powershell使用 个人记录
·
此文章为自用powershell时出现的问题(?)和解决方法(可能不是最优解)
- 从文件取得内容作为数组
- 定义方法
- 查询路径/文件是否存在
- 单行代码如何换行
- 参数传递
- 调用svn
- 调用bat脚本
- bat脚本中有pause时,如何自动跳过
#取得文件中内容
$file_data = Get-Content "xxx\test.txt" -Raw
#文件中内容用逗号分隔,所以用这样方式取得数组
#文件中内容示例:a,b,c
$names = $file_data -split ","
Function doSth(){
foreach($name in $names){
$result = (Test-Path $basePath$name ) -and (Test-Path $basePath$name.war) `
-and (Test-Path $basePath$name\gradlew.bat) -and (Test-Path $xxx)
if (!$result){
WriteLog -Msg "war/folder/bat Not Enough"
#这里好像未生效,有空查查
Return
}
}
#写log的方法 传递参数Msg
WriteLog -Msg "check ok"
}
Function UpdateSvn(){
cd "xxx\TortoiseSVN\bin\"
#循环更新svn
foreach($name in $names){
Start-Process -Wait -FilePath ".\TortoiseProc.exe" -ArgumentList "/command:update /path:$svnBase$sysName /closeonend:2"
}
}
#当用powershell调用的bat脚本中有pause时的解决方法
#RedirectStandardInput的参数可以是任意文件,此处利用了本程序调用必须得文件
Start-Process -FilePath "cmd.exe" -ArgumentList "/c .\update_war.bat" -Wait -RedirectStandardInput "C:\Users\Administrator\Desktop\War_Sysnms.txt" -NoNewWindow
更多推荐
所有评论(0)