MCPcopy Create free account
hub / github.com/Kitware/CMake / RunCommand

Function RunCommand

Source/cmExecProgramCommand.cxx:125–287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123
124namespace {
125bool RunCommand(std::string command, std::string& output, int& retVal,
126 char const* dir, bool verbose, Encoding encoding)
127{
128 if (cmSystemTools::GetRunCommandOutput()) {
129 verbose = false;
130 }
131
132#if defined(_WIN32) && !defined(__CYGWIN__)
133 // if the command does not start with a quote, then
134 // try to find the program, and if the program can not be
135 // found use system to run the command as it must be a built in
136 // shell command like echo or dir
137 if (!command.empty() && command[0] == '\"') {
138 // count the number of quotes
139 int count = 0;
140 for (char c : command) {
141 if (c == '\"') {
142 count++;
143 if (count > 2) {
144 break;
145 }
146 }
147 }
148 // if there are more than two double quotes use
149 // GetShortPathName, the cmd.exe program in windows which
150 // is used by system fails to execute if there are more than
151 // one set of quotes in the arguments
152 if (count > 2) {
153 cmsys::RegularExpression quoted("^\"([^\"]*)\"[ \t](.*)");
154 if (quoted.find(command)) {
155 std::string shortCmd;
156 std::string cmd = quoted.match(1);
157 std::string args = quoted.match(2);
158 if (!cmSystemTools::FileExists(cmd)) {
159 shortCmd = cmd;
160 } else if (!cmSystemTools::GetShortPath(cmd, shortCmd)) {
161 cmSystemTools::Error("GetShortPath failed for " + cmd);
162 return false;
163 }
164 shortCmd += " ";
165 shortCmd += args;
166
167 command = shortCmd;
168 } else {
169 cmSystemTools::Error("Could not parse command line with quotes " +
170 command);
171 }
172 }
173 }
174#endif
175
176 // Allocate a process instance.
177 cmsysProcess* cp = cmsysProcess_New();
178 if (!cp) {
179 cmSystemTools::Error("Error allocating process instance.");
180 return false;
181 }
182

Callers 1

cmExecProgramCommandFunction · 0.70

Calls 9

c_strMethod · 0.80
DecodeTextMethod · 0.80
appendMethod · 0.80
ErrorClass · 0.70
cmStrCatFunction · 0.70
FileExistsFunction · 0.50
emptyMethod · 0.45
findMethod · 0.45
matchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…