I am trying to install an exe created using Inno Setup.
When I try to install it using PowerShell with
Start-Process -wait C:updatefile.exe /VERYSILENT
all folders are created at proper places, registry values are created, but console hangs and does not return unless Ctrl+C is pressed.
But if I install exe using command prompt with
start /wait C:updatefile.exe /VERYSILENT
everything goes properly and command prompt returns.
What could be cause of this anomaly?
I need this exe to install through Dockerfile, but as PowerShell install is hanging, container does not install exe. Even with cmd
version in Dockerfile, container does not create install folders.
After checking logs I found that exe service is being started by installer in end. If that is reason for hanging, is there some argument I can use to exit PowerShell?
2
Answers
The
-Wait
switch of PowerShell’sStart-Process
cmdlet also waits for child processes of the launched process to exit[1], whereascmd.exe
‘s internalstart
command does not.Start-Process
also waiting for that (child) process to terminate indeed explains the hang.Here is a simple workaround:
When an executable is called via
cmd /c
,cmd.exe
implicitly waits until the executable’s process – and only it – terminates, even if it is a GUI application, just likestart /wait
would.Given the behavior described in footnote [1], another workaround is to use the
-PassThru
switch withStart-Process
(instead of-Wait
) and pipe the result toWait-Process
:[1] See GitHub issue #15555, which also discusses that
Wait-Process
acts differently in that only waits for the process itself to terminate.As zett42 points out, the behavior of
Start-Process -Wait
is now at least briefly mentioned in the docs as well (emphasis added): "waits for the specified process and its descendants".try
$arguments = "/Verysilent"
Start-Process -wait C:updatefile.exe -ArgumentList $arguments