How do I pass an equal sign when calling a batch script in Powershell?

前端 未结 6 1252
挽巷
挽巷 2020-12-06 05:04

We have a batch file that invokes our MSBuild-based build process. Syntax:

build App Target [ Additional MSBuild Arguments ]

Internally, i

6条回答
  •  再見小時候
    2020-12-06 06:04

    I don't know if there's an easier answer (I think not) but you can solve the problem by using .Net's process class to invoke cmd.exe. Here's an example:

    # use .NET Process class to run a batch file, passing it an argument that contains an equals sign. 
    # This test script assumes the existence of a batch file "c:\temp\test.bat"
    # that has this content:
    #      echo %1
    #      pause
    $cmdLine =  $cmdLine =  '/c c:\temp\test.bat "x=1"'
    $procStartInfo =  new-object System.Diagnostics.ProcessStartInfo("cmd", $cmdLine )
    $proc = new-object System.Diagnostics.Process
    $proc.StartInfo = $procStartInfo
    $proc.Start();
    

提交回复
热议问题