Start-Process and waiting

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 10 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
sctgmbh
Posts: 9
Last visit: Sat Dec 30, 2017 1:29 am

Start-Process and waiting

Post by sctgmbh »

Hello,

i found this thread via google and it does exactly match my problem.

When i compile the following two lines...
PowerShell Code
Double-click the code block to select all.
start-process notepad -wait
start-process calc
... an x86 exe wont wait and an x64 exe will wait to start the calculator until the notepad has been closed.

I compiled this small testscript into any possible type (commandline, forms (with and without STA), windows (with and without STA)) but the -wait won´t work with a x86 exe.

Is there anything i am doing wrong or another way to start another process and to wait for?
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Start-Process won't wait when compiled

Post by davidc »

Please post a new topic. If you need to refer to another post just provide a link. This way the original user doesn't get emails about someone else's questions and it prevents confusion on whose issue is what.

Thank you,

David
David
SAPIEN Technologies, Inc.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Start-Process and waiting

Post by davidc »

FYI, I moved this to a separate thread.


You need to use the -Wait parameter. Otherwise it will launch the process and continue to the next line of the script.

David
David
SAPIEN Technologies, Inc.
User avatar
sctgmbh
Posts: 9
Last visit: Sat Dec 30, 2017 1:29 am

Re: Start-Process and waiting

Post by sctgmbh »

I am using the -Wait parameter but is has no effect if i compile it into a x86 (32bit) exe.
If i compile it into a x64 (64bit) exe it is working as intended.

Can u reproduce that or am i doing something wrong?

Thanks in advance for your help.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Start-Process and waiting

Post by davidc »

What OS and PowerShell version are you using?

David
David
SAPIEN Technologies, Inc.
User avatar
sctgmbh
Posts: 9
Last visit: Sat Dec 30, 2017 1:29 am

Re: Start-Process and waiting

Post by sctgmbh »

To script and compile:
- windows 8 pro x64 (powershell 3)
- powershell studio 2012 3.1.22

Exe working as intended:
- windows 7 ultimate x64 (powershell 3) *
- windows 8 pro x64 (powershell 3)

Exe not working as intended:
- windows 7 pro x86 (powershell 3) *


* windows management framework 3 has been installed
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Start-Process and waiting

Post by davidc »

This could be a possible PowerShell v3 bug.

Try this and see if it works:
PowerShell Code
Double-click the code block to select all.
$process = Start-Process notepad -PassThru -Wait
$process.WaitForExit()

David
David
SAPIEN Technologies, Inc.
User avatar
sctgmbh
Posts: 9
Last visit: Sat Dec 30, 2017 1:29 am

Re: Start-Process and waiting

Post by sctgmbh »

davidc wrote:
PowerShell Code
Double-click the code block to select all.
$process = Start-Process notepad -PassThru -Wait
$process.WaitForExit()
Thank you very much. It works!
This topic is 10 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.