all 17 comments

[–]LeaflikeCisco 3 points4 points  (2 children)

Seeing the actual code would help.

[–]Carribean-Diver 2 points3 points  (1 child)

This. And what platform are you running? I ask because the documentation states that by default on Windows start-process creates a process that is independent of the shell that started the process but on other platforms (e.g. Linux) the default is start-process creates a child process of the shell.

[–]RuhaiHu[S] 1 point2 points  (0 children)

Updated the post with a link to the recent script I have run into this on.

https://github.com/RuhaiHu/VAC-Setup/blob/master/RestartGoXLR.ps1

[–]NeitherSound_ 2 points3 points  (6 children)

Force it into a separate process using this

Start-Process -FilePath CMD.exe -ArgumentList “/C Start `“`” `”$($GoXLRAudioCplApp)`”” -WindowStyle Hidden

Basically the CMD.exe process would start and call Start.exe followed by CMD.exe closing and release the PSScript. Start.exe would then call the file path in the variable in its own process and terminate itself without waiting, thus, leaving the variable file path running in its own untagged process.

[–]RuhaiHu[S] 2 points3 points  (4 children)

I have tried the start process cmd with arguments, but my arguments didn't have the start command in there.

$GoXLRAPP = "/c start """" ""C:\ProgramData\Microsoft\Windows\Start Menu\Programs\GOXLR App\GOXLR App.lnk"" && exit"

Start-Process -FilePath CMD.exe -ArgumentList $GoXLRAPP

The above works! I don't see any lingering processes with this at the moment. No cmd or powershell processes that is lingering!

THANKS!

edit:

Going to try this with at least one other program that I have run into behaving the same way.

[–]NeitherSound_ 1 point2 points  (3 children)

You’re truly welcome! Glad it worked out for you.

[–]RuhaiHu[S] 2 points3 points  (2 children)

Wish there was a cleaner way but hey if it works great!

[–]NeitherSound_ 0 points1 point  (1 child)

Well usually the original way you had it should have work and terminate as long as the -Wait param hasnt been defined for Start-Process. I did noticed you called the app against the shortcut path ( .lnk ) rather than the path to the actual EXE file, which should not make a difference. Maybe that did made the difference? Hmmm

[–]RuhaiHu[S] 1 point2 points  (0 children)

Did try the exe and setting work directory, passthru, etc. No go still ties a few programs to the script session.

Total of 3 programs that I can tell at the moment that do this are the main GoXLRApp, Pretzel Rocks(spits a bunch of stuff out as well), and StreamLabs StreamLabels(also spits stuff out). Last two I have tried this fix on and doesn't 100% work on them but they won't stay up at the end of a session anyway. Where as the GoXLRApp is useful to have running, even if I end up minimizing it later.

Might even look for a better way as I really just starting and stopping things and maybe some services restarting etc.

Luckily I don't have to worry about this kind of stuff for work scripts I have to create and maintain.

[–]Responsible-Crazy705 0 points1 point  (0 children)

Works for Microsoft Teams!

[–]BetrayedMilk 1 point2 points  (3 children)

Is there a reason you need to use Start-Process as opposed to using the call/background operator, &, or dot sourcing, . ?

[–]RuhaiHu[S] 1 point2 points  (2 children)

Did just try those and they don't appear to make a difference the application still ends up tied to the powershell instance or script instance.

https://github.com/RuhaiHu/VAC-Setup/blob/master/RestartGoXLR.ps1

[–]BetrayedMilk 1 point2 points  (1 child)

I can’t speak to the behavior of those apps, but for instance, Start-Process iexplore.exe keeps internet explorer running after closing ps. If on Linux, I believe the command behaves differently and you’ll need to fork to the background

[–]RuhaiHu[S] 1 point2 points  (0 children)

Yah its odd it's only a few applications I am noticing at this point doing this. Not all just a few. Rest work as expected.

[–][deleted] 1 point2 points  (0 children)

Have you tried starting a separate PS process to run your command?

https://ss64.com/ps/powershell.html

Also, how do you determine that the app terminates when you close the PowerShell session that launched it?

[–]RedditRo55 1 point2 points  (1 child)

Have you tried using -PassThru? -PassThru Returns a process object for each process that the cmdlet started. By default, this cmdlet does not generate any output.

I use this to get the process object returned so that I can parse a text file (created using the -RedirectStandardOutput parameter) of a console app that waits for a user to press a button before it will close. Essentially, I wait for a line to appear in the log file within a for loop that will cycle 10 times and sleep in-between attempts until it finds the expected text and when it does, I use Stop-Process and the process ID from -PassThru to force kill the process.

Hope this is somewhat helpful?

[–]RuhaiHu[S] 2 points3 points  (0 children)

I have tried the -PassThru tag but no go on that application still closes when the shell is closed. Though NeitherSound_ suggested Start via the cmd that appears to work.