// Copyright 2013 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. #include #include #define NOPLAN9DEFINES #include #include "win.h" int runcmd(char **argv) { // Mostly copied from ../cmd/dist/windows.c. // If there's a bug here, fix the logic there too. int i, j, nslash; Fmt fmt; char *q; WinRune *r; STARTUPINFOW si; PROCESS_INFORMATION pi; DWORD code; fmtstrinit(&fmt); for(i=0; argv[i]; i++) { if(i > 0) fmtprint(&fmt, " "); q = argv[i]; if(strstr(q, " ") || strstr(q, "\t") || strstr(q, "\"") || strstr(q, "\\\\") || (strlen(q) > 0 && q[strlen(q)-1] == '\\')) { fmtprint(&fmt, "\""); nslash = 0; for(; *q; q++) { if(*q == '\\') { nslash++; continue; } if(*q == '"') { for(j=0; j<2*nslash+1; j++) fmtprint(&fmt, "\\"); nslash = 0; } for(j=0; j