Sublime Forum

Powershell: how to block shell until ST is closed?

#1

Using notepad, you can do the following in Powershell…

notepad.exe | out-null; "finished!"

…and the shell will block execution until notepad is closed before printing “finished!”. However this doesn’t work with ST. This trick is useful if you want to edit a complex command from the shell. Is there a way of getting ST to behave like this too?

Cheers,
Guillermo

0 Likes

Problems with 7-zip integration as editor
#2

sublimetext.exe will, if there’s another instance running, pass the command line arguments to the existing process and exit immediately. I’m not at all familiar with powershell, but this is perhaps what’s causing the issue.

You can pass the undocumented --multiinstance on the command line to disable this behaviour, but this will cause some issues, as the two instances will overwrite each others settings.

0 Likes

#3

Passing the --multiinstance flag seems to work. Put the following in a script file like edit-cmdline-with-sublime.ps1:

[code]$line = (get-history -count 1).commandline
$tmp_file = [io.path]::GetTempFileName()
$line | add-content -path $tmp_file -encoding UTF8

set $editor to YOUR_PATH_TO_SUBLIME/sublimetext.exe

& $editor --multiinstance “$tmp_file” | out-null
[void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
[System.Windows.Forms.SendKeys]::SendWait((get-content $tmp_file))
remove-item $tmp_file[/code]

0 Likes