Skip to content

Commit b2964f2

Browse files
committed
patch 8.0.0501: on MS-Windows ":!start" does not work as expected
Problem: On MS-Windows ":!start" does not work as expected. Solution: When creating a process fails try passing the argument to ShellExecute(). (Katsuya Hino, closes #1570)
1 parent 3c2881d commit b2964f2

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

runtime/doc/os_win32.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,19 @@ A. You can't! This is a limitation of the NT console. NT 5.0 is reported to
212212
be able to set the blink rate for all console windows at the same time.
213213

214214
*:!start*
215-
Q. How can I run an external command or program asynchronously?
216-
A. When using :! to run an external command, you can run it with "start": >
217-
:!start winfile.exe<CR>
218-
< Using "start" stops Vim switching to another screen, opening a new console,
215+
Q. How can I asynchronously run an external command or program, or open a
216+
document or URL with its default program?
217+
A. When using :! to run an external command, you can run it with "start". For
218+
example, to run notepad: >
219+
:!start notepad
220+
< To open "image.jpg" with the default image viewer: >
221+
:!start image.jpg
222+
< To open the folder of the current file in Windows Explorer: >
223+
:!start %:h
224+
< To open the Vim home page with the default browser: >
225+
:!start http://www.vim.org/
226+
<
227+
Using "start" stops Vim switching to another screen, opening a new console,
219228
or waiting for the program to complete; it indicates that you are running a
220229
program that does not affect the files you are editing. Programs begun
221230
with :!start do not get passed Vim's open file handles, which means they do

src/os_win32.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4008,6 +4008,28 @@ vim_create_process(
40084008
}
40094009

40104010

4011+
static HINSTANCE
4012+
vim_shell_execute(
4013+
char *cmd,
4014+
INT n_show_cmd)
4015+
{
4016+
#ifdef FEAT_MBYTE
4017+
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
4018+
{
4019+
WCHAR *wcmd = enc_to_utf16((char_u *)cmd, NULL);
4020+
if (wcmd != NULL)
4021+
{
4022+
HINSTANCE ret;
4023+
ret = ShellExecuteW(NULL, NULL, wcmd, NULL, NULL, n_show_cmd);
4024+
vim_free(wcmd);
4025+
return ret;
4026+
}
4027+
}
4028+
#endif
4029+
return ShellExecute(NULL, NULL, cmd, NULL, NULL, n_show_cmd);
4030+
}
4031+
4032+
40114033
#if defined(FEAT_GUI_W32) || defined(PROTO)
40124034

40134035
/*
@@ -4711,6 +4733,7 @@ mch_call_shell(
47114733
STARTUPINFO si;
47124734
PROCESS_INFORMATION pi;
47134735
DWORD flags = CREATE_NEW_CONSOLE;
4736+
INT n_show_cmd = SW_SHOWNORMAL;
47144737
char_u *p;
47154738

47164739
ZeroMemory(&si, sizeof(si));
@@ -4729,6 +4752,7 @@ mch_call_shell(
47294752
cmdbase = skipwhite(cmdbase + 4);
47304753
si.dwFlags = STARTF_USESHOWWINDOW;
47314754
si.wShowWindow = SW_SHOWMINNOACTIVE;
4755+
n_show_cmd = SW_SHOWMINNOACTIVE;
47324756
}
47334757
else if ((STRNICMP(cmdbase, "/b", 2) == 0)
47344758
&& VIM_ISWHITE(cmdbase[2]))
@@ -4800,6 +4824,9 @@ mch_call_shell(
48004824
*/
48014825
if (vim_create_process((char *)newcmd, FALSE, flags, &si, &pi))
48024826
x = 0;
4827+
else if (vim_shell_execute((char *)newcmd, n_show_cmd)
4828+
> (HINSTANCE)32)
4829+
x = 0;
48034830
else
48044831
{
48054832
x = -1;

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
501,
767769
/**/
768770
500,
769771
/**/

0 commit comments

Comments
 (0)