Sublime Forum

Open new window from CLI also opens already open one +1 times

#1

I use Windows 10, I pin sublime text (SublimePortable\sublime_text.exe) to the task bar, always opening it after windows starts.
I also used to open folders from CLI after this, in ST3 the command looked like this:

SublimePortable\sublime_text.exe [path]

In ST4, since the previous command just focuses the already opened ST window, the command looks like this:

SublimePortable\sublime_text.exe -n [path]

Also tried, but same result:

SublimePortable\subl.exe -n [path]

Result:

  • The folder defined by [path] above opens in new window, that’s expected.
  • Often the last one from the already opened windows also gets reopened in a new window - totally duplicated, unwanted

Expected:

  • Only the folder defined by [path] should be opened in new window
0 Likes

#2

It sounds like what you’re experiencing here is the hot_exit setting being turned on (which it is by default). That causes Sublime to restore it’s state when you start it, such that if you quit Sublime while you have windows open, subl -n would start Sublime, create a new window and ALSO recreate the windows that used to exist.

Setting hot_exit to false (or if you’re using ST4, `“disabled”) stops the state of Sublime from being saved so that it won’t restore windows on startup.

Note however that this isn’t new in Sublime Text 4; Sublime has always behaved this way.

0 Likes

#3

Hot exit is a must-have feature, I would never turn it off.
The problem is, there is no “exit” in my case:

  1. Start Sublime from win tray icon (SublimePortable\sublime_text.exe)
  2. Start +1 Sublime window from CLI (SublimePortable\sublime_text.exe -n [path1])
  3. Start +1 Sublime window from CLI (SublimePortable\sublime_text.exe -n [path2])

What happens is:

  1. Sublime starts, windows from last session open
  2. Sublime opens path1 in new window + the currently active windows get duplicated!
  3. Sublime opens path2 in new window (no more duplications)

Actually, since my original post, I’ve discovered that on exit, the windows from (1) and from (2) are handled like they belonged to separate “sessions”. I mean, File/Exit does not close all the windows, only the windows started by (1) or (2), depending in which window did I click the File/Exit.

0 Likes

#4

On windows, you should be executing SublimePortable\subl -n [path] to have it communicate with the existing instance; using sublime_text there is making it try to execute a second copy, which is why it seems like multiple sessions, most likely.

0 Likes

#5

Also tried SublimePortable\subl -n [path], but with same results :frowning:

0 Likes

#6

The only other things that come to mind here would be if there were somehow multiple portable versions, since I beleive on Windows you can run multiple distinct copies of Sublime at once that way.

The easiest way to check that would be to check the first lines in the console, where the various paths for things are laid out; different portable versions would have different paths there (in this case, the relevant one would be the state path, since that is where the session information is stored).

1 Like

#7

Thank you very much, this was a bingo, here’s the problem:

Casing :man_facepalming:

I think these paths became case sensitive after ST4 upgrade, because I did not change either the shortcut, nor the CLi link.
However, now I use uppercase C drive letter in both, and now -n works as expected.

Thank you very much again!

0 Likes