I have a tool for editing the VersionInfo portion of our executables so that we can tie all of the different components to one installer part number. The tool I am using is resourcehacker (https://www.angusj.com/resourcehacker/) which supports command line arguments. However, they don't play well when used within a Powershell script.
The operation I am trying to complete is compiling the .rc file into a .res file that I can use at a later step. What is happening instead is that only the resourcehacker exe starts but the compile never happens.
A snip of what I have is as follows (it's ugly because I've been trying everything):
$rhPath = (Join-Path $CICDBaseScriptPath 'ResourceHacker.exe') #Path to rh.exe
$arg1 = "`'-open "
$arg2 = "`""
$arg3 = $ReplaceTTKVersionInfoRC # The name of the .rc file to be compiled
$arg4 = "`""
$arg5 = " -save `""
$arg6 = $TTKVersionInfoRes # The name of the output .res file
$arg7 = "`""
$arg8 = " -action compile`'"
$allArgs = $arg1,$arg2,$arg3,$arg4,$arg5,$arg6,$arg7,$arg8 -join ""
Start-Process -FilePath $rhPath -ArgumentList $allArgs
To run from the command line, I would need to have the following:
C:\> ResourceHacker.exe '-open "C:\agent_svc\_work\15\s\CICD\TTKVersionInfo_Temp.rc" -save "C:\agent_svc\_work\15\s\CICD\TTKVersionInfo.res" -action compile -log con'
When I run this from the commandline it works correctly. Also, from a powershell terminal interactively, if I run Start-Process with the same parameters, it will work. However, the Start-Process call does not seem to pass the arguments (because my .res file never changes) when called from inside the powershell script.
Can anyone please help me understand what needs to be done to get this to work?
'chars. around the embedded argument list; the same extraneous chars. are present in your "run from the command line" command. Sahil's answer doesn't address this problem and simply uses a single, single-line string literal without the extraneous characters instead. It also uses-NoWait,-NoNewWindowand-PassThruto make the execution synchronous, run in the same window, allow querying the exit code. However, direct invocation would make all this easier.