相关文章推荐
憨厚的篮球  ·  DB2 ...·  7 月前    · 
豪气的勺子  ·  ES时区问题-CSDN博客·  1 年前    · 
有爱心的书签  ·  spark ...·  1 年前    · 
精彩文章免费看

powershell & bash 脚本踩坑记录

    powershell 中执行外部程序(eg: exe程序)需要在语句前加 “&”

    & nginx.exe -s stop

    java 中执行powershell 获取正确的退出码执行命令

    powershell -file xxxxx.ps1

    java 中执行powershell路径必须是斜杠划分

    powershell -file C:/steve/test.ps1

  1. powershell 往注册表添加变量

  2. $newValue = New-ItemProperty -Path "HKLM:\SOFTWARE\ContosoCompany\" -Name 'HereString' -PropertyType MultiString -Value @"
    # 放置变量信息, 一定要换行才行
    
  3. powershell 读取文件并替换指定字符串
  4. # 替换一个
    ((Get-Content -path $src_filePath -Raw) -replace 'old_string', 'new_string') | Set-Content -Path $target_path
    # 替换多个
    ((Get-Content -path $src_filePath -Raw) -replace 'old_string', 'new_string' -replace 'old_2_str', 'new_2_str') | Set-Content -Path $target_path
    
  5. cmd 一次执行多个命令
  6. command1 && command2 && command3    # 三个命令以 ‘&&’分隔表示有执行依赖,只有当前面命令执行成功才会执行下一个命令,若不想有依赖关系,使用 ‘&’ 替换 ‘&&’
    
  7. ssh执行windows 相关命令,等同于以超级管理员的权限在本地cmd窗口执行命令(权限大)。

  8. 如果想要通过远程的方式在windows机器上以后台的方式启动某些应用,只能将应用打包成windows的服务
    才行。这是因为ssh远程结束后,所有通过ssh开启的后台任务都会随着ssh进程的结束而结束(皮之不存,毛