Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows の system("echo 1 > test") で test が出力されない。 #1079

Open
mattn opened this issue Sep 3, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@mattn
Copy link
Member

commented Sep 3, 2017

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Sep  4 2017 08:48:38)
MS-Windows 64 ビット コンソール 版
適用済パッチ: 1-1052

何もファイルが出力されない。いつからおかしかったんだろう。

@mattn

This comment has been minimized.

Copy link
Member Author

commented Sep 4, 2017

元からおかしかったっぽい。shellxquote が ( なのに echo 1 > test を括ってないのが原因。一応既存の動作を壊さない様にしたつもり。

diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 1cb15f204..83bd83c2b 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -1650,35 +1650,51 @@ make_filter_cmd(
 	STRCAT(buf, itmp);
     }
 #else
-    /*
-     * For shells that don't understand braces around commands, at least allow
-     * the use of commands in a pipe.
-     */
-    STRCPY(buf, cmd);
-    if (itmp != NULL)
+    if (*p_sxe != NUL && STRCMP(p_sxq, "(") == 0)
     {
-	char_u	*p;
-
-	/*
-	 * If there is a pipe, we have to put the '<' in front of it.
-	 * Don't do this when 'shellquote' is not empty, otherwise the
-	 * redirection would be inside the quotes.
-	 */
-	if (*p_shq == NUL)
+	if (itmp != NULL || otmp != NULL)
+	    vim_snprintf((char *)buf, len, "(%s)", (char *)cmd);
+	else
+	    STRCPY(buf, cmd);
+	if (itmp != NULL)
 	{
-	    p = vim_strchr(buf, '|');
-	    if (p != NULL)
-		*p = NUL;
+	    STRCAT(buf, " < ");
+	    STRCAT(buf, itmp);
 	}
-	STRCAT(buf, " <");	/* " < " causes problems on Amiga */
-	STRCAT(buf, itmp);
-	if (*p_shq == NUL)
+    }
+    else
+    {
+	/*
+	 * For shells that don't understand braces around commands, at least
+	 * allow the use of commands in a pipe.
+	 */
+	STRCPY(buf, cmd);
+	if (itmp != NULL)
 	{
-	    p = vim_strchr(cmd, '|');
-	    if (p != NULL)
+	    char_u	*p;
+
+	    /*
+	     * If there is a pipe, we have to put the '<' in front of it.
+	     * Don't do this when 'shellquote' is not empty, otherwise the
+	     * redirection would be inside the quotes.
+	     */
+	    if (*p_shq == NUL)
 	    {
-		STRCAT(buf, " ");   /* insert a space before the '|' for DOS */
-		STRCAT(buf, p);
+		p = vim_strchr(buf, '|');
+		if (p != NULL)
+		    *p = NUL;
+	    }
+	    STRCAT(buf, " <");	/* " < " causes problems on Amiga */
+	    STRCAT(buf, itmp);
+	    if (*p_shq == NUL)
+	    {
+		p = vim_strchr(cmd, '|');
+		if (p != NULL)
+		{
+		    /* insert a space before the '|' for DOS */
+		    STRCAT(buf, " ");
+		    STRCAT(buf, p);
+		}
 	    }
 	}
     }
@mattn

This comment has been minimized.

Copy link
Member Author

commented Sep 4, 2017

diff が大きそうに見えるけど、実際はこれを足しただけ

    if (*p_sxe != NUL && STRCMP(p_sxq, "(") == 0)
    {
	if (itmp != NULL || otmp != NULL)
	    vim_snprintf((char *)buf, len, "(%s)", (char *)cmd);
	else
	    STRCPY(buf, cmd);
	if (itmp != NULL)
	{
	    STRCAT(buf, " < ");
	    STRCAT(buf, itmp);
	}
    }
    else
    {
        /* 既存のコード */
    }

@mattn mattn referenced this issue Sep 4, 2017

Closed

端末機能について議論する #1057

20 of 21 tasks complete
@mattn

This comment has been minimized.

Copy link
Member Author

commented Sep 4, 2017

@k-takata

This comment has been minimized.

Copy link
Member

commented Sep 4, 2017

system("echo 1 > test") のテストがない?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.