此文章为自用powershell时出现的问题(?)和解决方法(可能不是最优解)

  1. 从文件取得内容作为数组
  2. 定义方法
  3. 查询路径/文件是否存在
  4. 单行代码如何换行
  5. 参数传递
  6. 调用svn
  7. 调用bat脚本
  8. 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

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐