MCPcopy Create free account
hub / github.com/Martchus/tageditor / runProcess

Method runProcess

cli/scriptapi.cpp:156–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154}
155
156QJSValue UtilityObject::runProcess(const QString &path, const QJSValue &args, int timeout)
157{
158 auto res = m_engine->newObject();
159#ifdef CPP_UTILITIES_HAS_EXEC_APP
160 auto pathUtf8 = path.toUtf8();
161 auto argsUtf8 = QByteArrayList();
162 auto argsUtf8Array = std::vector<const char *>();
163 if (args.isArray()) {
164 const auto size = args.property(QStringLiteral("length")).toUInt();
165 argsUtf8.reserve(static_cast<QByteArrayList::size_type>(size));
166 argsUtf8Array.reserve(static_cast<std::size_t>(size) + 2);
167 for (auto i = quint32(); i != size; ++i) {
168 argsUtf8.append(args.property(i).toString().toUtf8());
169 }
170 }
171 argsUtf8Array.emplace_back(pathUtf8.data());
172 for (const auto &argUtf8 : std::as_const(argsUtf8)) {
173 argsUtf8Array.emplace_back(argUtf8.data());
174 }
175 argsUtf8Array.emplace_back(nullptr);
176 auto output = std::string(), errors = std::string();
177 try {
178 auto exitStatus = CppUtilities::execHelperAppInSearchPath(pathUtf8.data(), argsUtf8Array.data(), output, errors, false, timeout);
179#ifndef CPP_UTILITIES_BOOST_PROCESS
180 if (WIFEXITED(exitStatus)) {
181 exitStatus = WEXITSTATUS(exitStatus);
182 res.setProperty(QStringLiteral("status"), exitStatus);
183 }
184#else
185 res.setProperty(QStringLiteral("status"), exitStatus);
186#endif
187 } catch (const std::runtime_error &e) {
188 res.setProperty(QStringLiteral("error"), QString::fromUtf8(e.what()));
189 }
190 res.setProperty(QStringLiteral("stdout"), QString::fromStdString(output));
191 res.setProperty(QStringLiteral("stderr"), QString::fromStdString(errors));
192#endif
193 return res;
194}
195
196QString UtilityObject::formatName(const QString &str) const
197{

Callers

nothing calls this directly

Calls 2

toStringMethod · 0.80
dataMethod · 0.45

Tested by

no test coverage detected