美文网首页
powershell & bash 脚本踩坑记录

powershell & bash 脚本踩坑记录

作者: 兴厚 | 来源:发表于2019-05-22 17:55 被阅读0次
    1. powershell 中执行外部程序(eg: exe程序)需要在语句前加 “&”

      & nginx.exe -s stop

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

      powershell -file xxxxx.ps1

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

      powershell -file C:/steve/test.ps1

    4. powershell 往注册表添加变量

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

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

    相关文章

      网友评论

          本文标题:powershell & bash 脚本踩坑记录

          本文链接:https://www.haomeiwen.com/subject/tyzuzqtx.html