Home Download Buy Blog Forum Support

Powershell: how to block shell until ST is closed?

Powershell: how to block shell until ST is closed?

Postby guillermooo on Wed Feb 03, 2010 8:52 pm

Using notepad, you can do the following in Powershell...

Code: Select all
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
guillermooo
 
Posts: 718
Joined: Thu Jul 23, 2009 9:06 am

Re: Powershell: how to block shell until ST is closed?

Postby jps on Wed Feb 03, 2010 9:38 pm

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.
jps
Site Admin
 
Posts: 3058
Joined: Wed Mar 19, 2008 12:33 pm

Re: Powershell: how to block shell until ST is closed?

Postby guillermooo on Wed Feb 03, 2010 11:44 pm

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

Code: Select all
$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
guillermooo
 
Posts: 718
Joined: Thu Jul 23, 2009 9:06 am


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 18 guests