Home > Net >  Converting .Bat files process in PowerShell
Converting .Bat files process in PowerShell

Time:02-25

two Bat files commands to convert into a PowerShell :

call "%CMD_Env_Path%\vcvarsall.bat" x86

call %BUILD_DIR%\TFBf.bat %1 %2 %3 %4

CodePudding user response:

To retrieve Environment Variables in PS use:

$env:[environment variable name]

Example:

PS> $env:ComSpec
C:\WINDOWS\system32\cmd.exe

CodePudding user response:

The simplest solution is to delegate to cmd.exe via its CLI (using the /c parameter).

The following assumes that that the first 4 positional arguments received by your PowerShell script are to be passed through to the TFBf.bat batch file, analogous to %1 %2 %3 %4 in your question:

cmd /c @"
call "%CMD_Env_Path%\vcvarsall.bat" x86 && call "%BUILD_DIR%\TFBf.bat" $($args[0..3].ForEach({ '"{0}"' -f $_ }))
"@
  • Related