Wie übergibt man den Pfad mit Leerzeichen-script

Ich versuche PowerShell verwenden, rufen Sie eine EXE-Datei, die an einem Speicherort/Pfad mit Leerzeichen. Wenn ich rufen Sie das Skript von der Kommandozeile aus, die EXE-Datei der vollständige Pfad ist nicht an das Skript übergeben. Alle Ideen, warum dies geschieht?

PowerShell-Skript Inhalt (Untitled1.ps1)

Hier ist der gesamte script, das wird von der Kommandozeile aufgerufen:

param(
    [string] $ParamExePath
)

function Run-CallThisExe {
    param(
        [string] $ThisExePath
    )

    Write-Host "ThisExePath: " "$ThisExePath"
    start-process -FilePath $ThisExePath
}

write-host "ParamExePath: " $ParamExePath

Run-CallThisExe -ThisExePath "$ParamExePath"

Befehlszeilen-Zeichenfolge

Hier ist die Befehlszeilen-Zeichenfolge ausführen von PowerShell-Skript, das den übergeordneten Ordner:

powershell -command .\Untitled1.ps1 -NonInteractive -ParamExePath "C:\path with spaces\myapp.exe"

Ausgabe

Ist das, was hier ausgegeben wird, nachdem das Skript ausgeführt

ParamExePath:  C:\path
ThisExePath:  C:\path

start-process : This command cannot be run due to the error: The system cannot
find the file specified.
At C:\sample\Untitled1.ps1:11 char:5
+     start-process -FilePath $ThisExePath
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

InformationsquelleAutor Michael | 2015-09-01

Schreibe einen Kommentar