代码之家  ›  专栏  ›  技术社区  ›  JcMaltaDev

启动进程上虚假的“进程列表”输出

  •  0
  • JcMaltaDev  · 技术社区  · 5 年前

    在ps1脚本中,我有以下内容:

    Write-Host "MySqlDump Running"
    $runProg = "C:/Program Files/MariaDB 10.4/bin/mysqldump.exe"
    $runArgs = "JcTest --user=JcTest --password=JcTestPass --databases=TRUE --host=localhost --port=23246"
    Start-Process -FilePath $runProg -ArgumentList $runArgs -RedirectStandardOutput "backup.sql" -Wait -PassThru -NoNewWindow
    Write-Host "MySqlDump Finished"
    
    backupFolder "C:\Backups" # A routine in a .psm1 module to create a 7Zip of a complete folder
    

    执行时,控制台输出如下:

    [C:\...\JCPrompt]> .\backupProj.ps1
    MySqlDump Running
    
     NPM(K)    PM(M)      WS(M)     CPU(s)      Id  SI ProcessName
     ------    -----      -----     ------      --  -- -----------
          7     3.47       6.05       0.02   29524   1 mysqldump
    MySqlDump Finished
    
    
    7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21
          5     0.73       3.18       0.00   25332   1 7za
    [C:\...\JcPrompt]> Scanning the drive:
    367 folders, 1313 files, 92447874 bytes (89 MiB)
    

    控制台输出中似乎混入了虚假的进程列表。还要注意7zip输出中间的PS提示。这在执行后立即出现 Start-Process 电话。

    最后,此脚本还需要 <enter> 最终返回PS提示。

    任何线索都将是最受欢迎的!

    备份文件夹的来源:

    [CmdletBinding()]
    Param(
        [Parameter(Mandatory = $true, Position = 0)]
        [string]$folderName
    )
    
    Set-StrictMode -Version Latest
    
    $folderCurrent = (Get-Location).Path + "\"
    
    Set-Location $folderName
    $folderBase = (Get-Location).Path + "\"
    $folderName = $folderBase.Split("\" )[-2]
    
    Do_dsBackup ($folderBase + "*.*") ( $pathBackups + "\" + $folderName + '-' + (Get-dsShortDate))
    
    Set-Location $folderCurrent
    
    ----------
    
    function Do_dsBackup ( [String]$7zipSrc, [String]$7zipDest)
    {
        if (-not $7zipSrc.StartsWith('"')) { $7zipSrc = Get-dsQuoted( $7zipSrc) }
        if (-not $7zipDest.StartsWith('"')) { $7zipDest = Get-dsQuoted( $7zipDest) }
    
        Start-Process -Wait -NoNewWindow -RedirectStandardOutput=".\NUL" -FilePath "c:\4dos\7za.exe" -ArgumentList "a -r -y", $7zipDest, $7zipSrc
    }
    
    0 回复  |  直到 5 年前
    推荐文章