Ejemplo n.º 1
0
        private static StringBuilder BuildCommandLine(ProcessStartInfo startInfo)
        {
            // Construct a StringBuilder with the appropriate command line
            // to pass to CreateProcess.  If the filename isn't already
            // in quotes, we quote it here.  This prevents some security
            // problems (it specifies exactly which part of the string
            // is the file to execute).
            StringBuilder       commandLine = new StringBuilder();
            ReadOnlySpan <char> fileName    = startInfo.FileName.AsSpan().Trim();
            bool fileNameIsQuoted           = fileName.Length > 0 && fileName[0] == '\"' && fileName[fileName.Length - 1] == '\"';

            if (!fileNameIsQuoted)
            {
                commandLine.Append('"');
            }

            commandLine.Append(fileName);

            if (!fileNameIsQuoted)
            {
                commandLine.Append('"');
            }

            startInfo.AppendArgumentsTo(commandLine);

            return(commandLine);
        }