#include "mainwindow.h"
#include "mainwindow.h"
#include <QApplication>
#include <QProcess>
#include <QDir>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QProcess process;
process.setProgram("bash");
process.setArguments({"-c","pyls"});
auto procEnv = process.processEnvironment();
QString userRuntimeBinPath = QDir::homePath() + QDir::separator() + ".local"
+ QDir::separator() + "bin";
QString userPythonPkgPath = QDir::homePath() + QDir::separator() + ".local"
+ QDir::separator() + "lib"
+ QDir::separator() + "python3.7"
+ QDir::separator() + "site-packages";
procEnv.insert("PYTHONPATH=%0", userPythonPkgPath);
QString PATH_EnvValue = procEnv.value("PATH");
procEnv.remove("PATH");
procEnv.insert("PATH", userRuntimeBinPath + ":" + PATH_EnvValue);
process.setProcessEnvironment(procEnv);
qInfo() << procEnv.value("PATH");
QObject::connect(&process, &QProcess::readyReadStandardOutput, [&process](){
qInfo() << process.readAllStandardOutput();
});
QObject::connect(&process, &QProcess::readyReadStandardError, [&process](){
qInfo() << process.readAllStandardError();
});
QObject::connect(&process, QOverload<QProcess::ProcessError>::of(&QProcess::error),
[&process](QProcess::ProcessError err){
qInfo() << err << process.errorString();
});
process.start();
process.waitForStarted();
process.write("Content-Length: 63\r\n\r\n{\"jsonrpc\": \"2.0\", \"id\": 1, \"method\": \"shutdown\", \"params\": {}}");
return a.exec();
}
QProcess 启动 python-language-server (pyls)
最新推荐文章于 2024-08-13 08:40:05 发布