Share via


powershell start-process with wait option never finishes

Question

Thursday, June 7, 2012 11:50 PM

Hi,

I am using using a backup product called Commvault (version 9/SP6a).

I am running a Commvault command "qmedia -b XX2201L4 -el 'Offsite'".

This runs OK from the powershell interactive prompt.

I have put the following in a powershell script file:

$export="qmedia"

$exportarg=" -b XX2201L4 -el 'Offsite'"

start-process $export $exportarg -wait

write-host "done"

However I never get the "done" display on my screen. I see that start-process creates a new window but that window never goes away even when the "qmedia" command has done its work.

How do I fix this?

All replies (6)

Friday, June 8, 2012 12:27 PM âś…Answered

You can try running some PSDebug and PSBreakpoints on it. Try these commands if you are not familiar with how to set it up:

PS > Set-PSBreakpoint -Line (2..4) -Script C:\whateveryourpath\is.ps1
PS > Set-PSDebug -Trace 2

To then execute your script 

PS > C:\whateveryourpath\is.ps1

When it runs you will see some yellow output (because debug is turned on) and it will stop on lines 2, 3, and, 4. When it stops, you can query around by looking at variables, checking processes, etc to determine more about the current workings of the script than simply having it run and fail. Also, you can use Write-Debug to get a similar insight, but, it doesn't allow you to view pipeline objects as execution time.

Lastly, you may need to write your standard error and output to file to see if there is anything you are not catching because it's running in a different window. To short cut that process, try the -NoNewWindow option. If errors occur or there is some response from the .exe you should see it in the console.


Friday, June 8, 2012 12:12 AM

Perhaps specifying the full path to the product with the extension would help in the $export object.


Friday, June 8, 2012 1:48 AM

I have now tried using the full path to "qmedia" and the same thing happens!


Friday, June 8, 2012 2:49 AM

a few questions and suggestions:

  1. In addition to giving the complete path to qmedia, I'd suggest including the -filepath and -argumentlist parameter names.
  2. Can you tell if it is receiving the parameters you intend to pass to it?
  3. You say you can run the command from the powershell prompt. What happens when you run it from the prompt using start-process and literal parameters?
  4. what happens if you leave off the -wait - does the window eventually close?
  5. what happens if you just put the qmedia command in the script (i.e. without using start-process?
  6. What window is it that start-process opens and then does not close?

If qmedia runs OK from a powershell script without using start-process, but you need start-process because of the -wait functionality, then perhaps your main script could use start-process to start powershell to run anothe script that contains just the qmedia command.

Al Dunbar


Wednesday, March 13, 2013 11:14 AM

I am having a similar problem.  I do start-process on dism (with full path, argument list, wait and nonewwindow).  The first time my scripts runs this cmdlet, it will never finish.  I have replaced the first call (which does a /mount-wim) with a simple "&" running and it works.

Seems to me like start-process is suffering some severe .net process features...

PS C:\OPK> get-host

Name             : ConsoleHost
Version          : 3.0
InstanceId       : 3c3c692a-dadd-411a-a9d6-c5a0a4a66e6b
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : de-DE
CurrentUICulture : de-DE
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

I'm running this in a virtual box windows 7 professional, updated PowerShell to v3.0.

P.S.: PowerShell 3.0 has issues with its offline help (Update-Help as Administrator does not work well)


Friday, November 15, 2013 2:47 PM | 3 votes

Hello

I had this issue when trying to batch Adobe Flash CS 5.5. The issue is apparently, that -wait waits for the whole process group to finish. In case of Flash, it spawns the Adobe CS5 Extension Manager, which does not end when the Flash process exits. If I killed the Extension Manager, the start-process would return.

I tried two approaches which both circumvent this issue:

You can either create a process object using new-object System.Diagnostic.Process etc. (the web should provide enough examples how to do that).

or, the much simpler way

use start-process -passthru instead of -wait, save the returned process in a variable and use WaitForExit(), like this:

$p=start-process -passthru $path_to_my_program$p.WaitForExit()

Hope this helps anyone.

Cheers

Ulf