Re-write this batch file in powershell: setlocal ENABLEDELAYEDEXPANSION set…
- User
Re-write this batch file in powershell:
setlocal ENABLEDELAYEDEXPANSION
set "filename=%~1"
SET "executable_path=%~2" SET kill_timeout=%~3 echo %%calc=$name=%filename% > "%TEMP%\a.pci" type "%~dp0RunSinglePpf.pci" >> "%TEMP%\a.pci"
set Regtest=1
powershell -ExecutionPolicy Bypass -File "%~dp0\runwithtimeout.ps1" -ProgramName "%executable_path%" -PciName "%TEMP%\a.pci" -TimeoutSeconds %kill_timeout% rem start "A" /wait "%executable_path%" "%TEMP%\a.pci"
endlocal
- Assistant
Here's a PowerShell script equivalent to the provided batch file:
# Make sure all arguments are present param ( [string]$Filename, [string]$ExecutablePath, [int]$KillTimeout ) # Cancel the whole script if not all parameters are present if (-not $Filename -or -not $ExecutablePath -or -not $KillTimeout) { Write-Host "Usage: script.ps1 <filename> <executable_path> <kill_timeout>" exit } # Construct the path for the temporary "a.pci" file in the TEMP directory $TempPciPath = Join-Path -Path $env:TEMP -ChildPath "a.pci" # Write to the temporary "a.pci" with the provided filename "$(`$calc=$name=$Filename)" | Set-Content -Path $TempPciPath # Append the contents of "RunSinglePpf.pci" to the temporary PCI file $RunSinglePciPath = Join-Path -Path $PSScriptRoot -ChildPath "RunSinglePpf.pci" Get-Content -Path $RunSinglePciPath | Add-Content -Path $TempPciPath # Set a flag variable called 'Regtest' to 1 (not used in this script, but set for parity with batch) $Regtest = 1 # Call the PowerShell script "runwithtimeout.ps1" with the proper arguments $ScriptPath = Join-Path -Path $PSScriptRoot -ChildPath "runwithtimeout.ps1" & powershell -ExecutionPolicy Bypass -File $ScriptPath -ProgramName $ExecutablePath -PciName $TempPciPath -TimeoutSeconds $KillTimeout # Normally you would clean up the temporary file after execution, like: # Remove-Item -Path $TempPciPath