Vyhľadajte odpoveď

Vyhnite sa podvodom s podporou. Nikdy vás nebudeme žiadať, aby ste zavolali alebo poslali SMS na telefónne číslo alebo zdieľali osobné informácie. Nahláste prosím podozrivú aktivitu použitím voľby “Nahlásiť zneužitie”.

Learn More

Start firefox in a new window from the command line and wait for the user to close it.

  • 13 odpovedí
  • 1 má tento problém
  • 1 zobrazenie
  • Posledná odpoveď od FredMcD

more options

I would like to spawn a new instance of Firefox in a new window from a script file (python on MS windows 7) and then wait till the user closes the the Firefox window to continue the execution of my script. There are some things I have to do in my script only after Firefox has closed. (I have to do the same for IE and Chrome).

As a test, I tried to start Firefox manually on the command line with various options and have not hit on the right options. I can get Firefox to open in a new window fine (-new-window option) but could not get it to wait for the window to close to return execution to the cmd window - it would return as soon as the Firefox window was opened.

https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options mentions a -fwait command line option but does not describe it and I didn't see any effect when I tried to use it (if I was using it correctly).

Any ideas?

I would like to spawn a new instance of Firefox in a new window from a script file (python on MS windows 7) and then wait till the user closes the the Firefox window to continue the execution of my script. There are some things I have to do in my script only after Firefox has closed. (I have to do the same for IE and Chrome). As a test, I tried to start Firefox manually on the command line with various options and have not hit on the right options. I can get Firefox to open in a new window fine (-new-window option) but could not get it to wait for the window to close to return execution to the cmd window - it would return as soon as the Firefox window was opened. https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options mentions a -fwait command line option but does not describe it and I didn't see any effect when I tried to use it (if I was using it correctly). Any ideas?

Všetky odpovede (13)

more options

There is a /wait option for the Windows "start" command to wait for the program to get finished.

/wait   : Starts an application and waits for it to end. 
more options

Dos has many good programs, but Windows sometimes hides them.

more options

Thank you for your response

I did try something like:

start "" /WAIT "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" "-new-window" "http://stackoverflow.com"

This does not wait for the user to close the browser window if firefox is already running. It will wait if firefox is not already running.

You can cut and past the above line into a cmd and try it. If firefox is already running a new browser window will open and the command prompt will quickly become available again for user input.


I think what is happening is something like this...

1) The start /WAIT command starts a new process (A) and is told to wait till that process terminates. Process A in this case is firefox.exe.

2) Firefox then checks to see if an instance of firefox is already running and, if it is, it uses that instance to open a new browser window and then terminates itself - process A will end (CASE 1). If firefox is not already running then the process A opens a browser window and displays the requested URL (CASE 2).

3) In CASE 1 process A is terminated and the "start" command thinks its work of waiting is done and it terminates allowing the command line to become available for user input again. If you look at the processes in the task manager you will see only one instance of firefox running but you will have more than one browser window open.

4) In CASE 2 process A is not terminated until the user closes the browser window and only then is execution focus returned to the cmd prompt (the desired effect for my case).

So it looks like the exact same command has different behavior based on the current execution state of firefox.

I did read "If you would like to also allow multiple instances of Firefox to run at the same time, add "-no-remote" after the profile name." on the following page: https://developer.mozilla.org/en-US/docs/Mozilla/Multiple_Firefox_Profiles

I tried adding the "-no-remote" option to the above command (CASE 1) but without specifying a profile but it said: "Firefox is already running, but is not responding. To open a new window, you must first close the existing Firefox process or restart your system"

(NOTE: Another firefox process was running but it was still responsive.)

So my guess is that - though not explicitly stated - the user must specify a profile in order to run firefox in a new process. It is problematic for me to require all my potential users to create a new firefox profile and expose it to my code so I can run firefox as a stand-alone process.

If this is the case - I guess the question becomes: Can I programmatically create a temporary firefox profile, use it to execute firefox in a separate instance and then delete the profile once the user terminates the firefox process? (sounds kind-a messy)

Any other ideas that I might consider?

more options

I tested, and this works. NOTE the placement of the quotes.

Start "=<name for window>=" "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -new-window http://stackoverflow.com /WAIT

NOTE: the name for window is required, but in my test, it did not display.

more options

Thank you again for your response.

I am still having troubles though:

I cut-and-pasted your command line straight from the browser to a cmd window. The command started firefox and returned immediately - making the command prompt available for user input. It did not matter if firefox was already running or not. I need the start command to wait until firefox is closed by the user.

I believe there is a syntax error in your command. Your start command was given as:

Start "=<name for window>=" "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -new-window http://stackoverflow.com /WAIT The syntax of the command is something like (http://ss64.com/nt/start.html):

START "title" path [options] "command" [parameters]

  title       Text for the CMD window title bar (required.)
  path        Starting directory.
  command     The command, batch file or executable program to run.
  parameters  The parameters passed to the command.

(In my previous post my title was an empty string, i.e., "")

/WAIT is an option for the start command and should come before the "command" that is being spawned. The parameters following the "command" being spawned are passed to the "command".

In essence you are trying to start firefox as:

"C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -new-window http://stackoverflow.com /WAIT

which will start firefox fine because it will politely ignore the /WAIT command line option - but it won't wait.


If I re-arrange your command line so the /WAIT is in the proper place:

Start "=<name for window>=" /WAIT "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -new-window http://stackoverflow.com

The behavior becomes exactly like I described in my previous post - returning immediately if firefox is already running and waiting if the start command is starting the first instance of firefox.

I do not believe there is a problem with the start command. It seems to be doing what it was designed to do when the /WAIT option is selected. I think the new firefox process detects that another instance of firefox is running and lets the existing instance open the newly requested URL and then the new instance terminates itself. I think the waiting start command does what is supposed to do and quits waiting because the process it started has terminated.

I also think firefox is also doing exactly what it was designed to do (at least by default) but I need it to wait to terminate until the user closes the bowser window that was programmatically requested to be displayed. (What I need is really the "normal" or at least the "more-common" behavior of program execution.)

Again, this is my guess of what is going on, but it seems consistent with behavior of the start command waiting if firefox is not already running and not waiting firefox is already running. Also, even after the new browser window is opened, the task manager still reports only one instance of firefox running.

So how do I get firefox to let me start a new instance, whether one is running already or not, and then wait until the user terminates the process by closing the window?

Thanks again for your help.

more options

Let's see. When Firefox is running, it only has one process running in the Windows Task Managers; Processes window. But the Applications window will show each window that Firefox has open.

It could be that is the cause of the problem.

I will try a few things and see what happens.

more options

I have tried several combinations using /I /Separate. None Work. I did find this, however;

When executing an application that is a 32-bit GUI application, CMD.EXE does not wait for the application to terminate before returning to the command prompt. This new behavior does NOT occur if executing within a command script.


There is a utility program that will do what you want. Its command is;

nircmd.exe waitprocess firefox.exe speak text "Firefox was closed"

If you want, I will tell you where to find it.

more options

Thanks for the reply,

If there is not current firefox execution running on the machine then the start /WAIT command functions as expected, waiting for the new firefox process to terminate. It looks like that if firefox is already running, the new process that "start" created hands the job of displaying the requested URL over to the existing firefox process and then terminates itself. start /WAIT then terminates because the process it was waiting for has now ended.

It seems that waiting for the process is functioning as expected (i.e., "start /WAIT" is doing it's job). In order to get the new firefox execution to take responsibility for displaying the requested URL firefox must be told to act independently of any existing firefox execution. It seems to me that this must be an instruction to firefox since it is what is deciding to, by default, to maintain only one instance of itself. The discussion of multiple profiles seems to touch on this topic but forcing my potential users to each create and maintain as separate profile is problematic. That is why I mentioned above about dynamically creating a temporary profile for a user and then deleting it when the firefox execution is terminated. I could not see a means of doing this in the online help.

So the question remains:

I there a way to start firefox in a new window from the command line and wait for the user to close it? The new instance of firefox needs to be independent from any other firefox process.

Any ideas?

more options

Go to the Mozilla Add-ons Web Page {web link} (There’s a lot of good stuff here) and search for what you want.

more options

Can you tell me briefly what you want the extra Firefox to do, in general?

more options

I would like start Firefox from a script, displaying a URL provided on the command line, and then have it wait until the user closes the window displaying the requested URL. Once Firefox has terminated my script can then proceed with subsequent steps in my process.

more options

Well I think I have a "fix" of sorts but it is kinda clunky. The example here was implemented in a windows batch file. Here is what I got - see what you guys think...

As a preliminary step, I need to create a Firefox user profile that is stored in a directory that will be part of my code distribution. This should only need to be done once. (Doing it this way saves my users from having to make their own new user profile.) Ref: Callum Mcdonald's Blog and MozillaZine: Command line arguments (I thought about programmatically creating a new temporary user profile for the user on-the-fly but I couldn't figure out how to do it.)

The execution procedure would go something like this:

  1. Copy the Firefox user profile directory from the distribution to the user's analysis work area, renaming it to have a unique directory name (Append the PID?, date?, random number?).
  • robocopy "C:\Dan\DEV\web\sandbox\firefox_profile" "C:\Dan\DEV\web\sandbox\temp_profile" /E


  1. Execute Firefox specifying the desired URL, the local copy of the profile, and "-no-remote" keyword.
  • "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -new-window http://stackoverflow.com -no-remote -profile "C:\Dan\DEV\web\sandbox\temp_profile"


Script execution will wait here until this new instance of Firefox is closed by the user.


  1. Delete the user's copy of the Firefox profile.
  • RD /S /Q "C:\Dan\DEV\web\sandbox\temp_profile


  1. Continue with subsequent process steps...


I am pretty sure this is not what the developers of Firefox envisioned but it seems to work.

Some potential problems:

  • It has some "supportability" issues since I don't know if the version of the user profile provided by me in the distribution is compatible with the version of Firefox the user is running. (I thought about providing PortableFirefox in the distribution to try and avoid this but I was worried about code-bloat in the distribution.)
  • The user isn't going to view Firefox using his own default profile which they are use to. (I thought about trying to copy the user's own default profile into the temporary profile directory like above but I couldn't figure out how to query Firefox for the location and name of the default user profile.)
  • The whole process is just sloppy.

Thanks for all your feedback so far.

Any comments or ideas?

more options

Hmm. Very nice.

Read this article. It can tell you how to have Firefox start using other profiles. If the users profile is accessible, then they can make any changes they want, and only that one profile is affected.

https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options#-ProfileManager_or_-P