0

Currently have around 50 URL's which we need to periodically view randomly on a wall mounted TV in work along with 6 URL's which must always be up and available. Plan is to choose a random URL from the list of 50 and display it for 30 seconds in Firefox, then kill the process and choose another URL to automatically open in its predecessors place, but always maintaining the other 6 Firefox instances in the background. Problem I am having is that the PowerShell code shows the PID of the new Firefox instance but the PID is not present in Task Manager so does not close, and we end up with too many pages open. No idea how to resolve this, any ideas welcome, though a Powershell related resolution would be preferred.

Tab rotator would not work as we had way too many tabs open. Tried implementing a time based script so any Firefox instance over 30 seconds but less than 1 minute would be killed, however this always seemed to kill all Firefox instanced including the 6 which must always be available.

Part of the PowerShell code is below:

$bb = 1

$app = Get-Content $importPath |
       Get-Random -Count $bb |
       ForEach-Object {Start-Process -PassThru $_}

Wait-Process $app.Id

Write-Host $app.Id

Start-Sleep -Seconds 30

Stop-Process $app

Current script shows me the PID from 'Write-Host $app.Id' in ISE however, that PID is not present in Task Manager, so wondering if this is a Firefox related issue as oppose to POSH. Expected outcome would be that PS kills the explicit PID and a new random URL is spawned in Firefox.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • I don't know about Firefox specifically, but it's not uncommon for browser executables to simply activate an preexisting process or even spawn another process and asynchronously delegate the work to it, meaning that the process at hand is very short-lived and doesn't represent the actual process that does the work. Also, please [format your code and sample input/output properly](http://meta.stackexchange.com/a/22189/248777). – mklement0 Nov 09 '19 at 19:04
  • 1
    for your use case i would either [1] use selenium and one of the powershell modules for it, OR [2] use AutoIT or AutoHotKey to automate the GUI of each firefox instance. – Lee_Dailey Nov 09 '19 at 19:37
  • Thanks for the advice, much appreciated. – CharlieJones Nov 09 '19 at 22:29

1 Answers1

0

You could try forcing it to open in a separate process by specifying a profile for the scirpt rotating instances of Firefox, and a separate profile for your 6 pages: Is there a way to force Firefox to launch in a new process?

This covers using the -p to specify profiles, and apparently separate profile instances will be separate processes.

Use -P to manually create a profile like "Script" and another like "AlwaysOn" one time, and then use -p Script to launch from your script. Use -p AlwaysOn to launch the 6 background tabs and see if that keeps the processes separated.

Josh
  • 170
  • 7