mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
458113f8f9
* Improve utils code style * Fix indendation Co-authored-by: brindosch <edeltraud70@gmx.de>
76 lines
1.5 KiB
C++
76 lines
1.5 KiB
C++
#ifdef _WIN32
|
|
#include <utils/Logger.h>
|
|
#include <QString>
|
|
#include <QByteArray>
|
|
namespace Process {
|
|
|
|
void restartHyperion(bool asNewProcess){}
|
|
|
|
QByteArray command_exec(QString /*cmd*/, QByteArray /*data*/)
|
|
{
|
|
return QSTRING_CSTR(QString());
|
|
}
|
|
};
|
|
|
|
#else
|
|
|
|
#include <utils/Process.h>
|
|
#include <utils/Logger.h>
|
|
|
|
#include <QCoreApplication>
|
|
#include <QStringList>
|
|
|
|
#include <unistd.h>
|
|
#include <cstdio>
|
|
#include <iostream>
|
|
#include <memory>
|
|
#include <stdexcept>
|
|
|
|
namespace Process {
|
|
|
|
void restartHyperion(bool asNewProcess)
|
|
{
|
|
Logger* log = Logger::getInstance("Process");
|
|
std::cout << std::endl
|
|
<< " *******************************************" << std::endl
|
|
<< " * hyperion will restart now *" << std::endl
|
|
<< " *******************************************" << std::endl << std::endl;
|
|
|
|
|
|
QStringList qargs = QCoreApplication::arguments();
|
|
int size = qargs.size();
|
|
char *args[size+1];
|
|
args[size] = nullptr;
|
|
for(int i=0; i<size; i++)
|
|
{
|
|
int str_size = qargs[i].toLocal8Bit().size();
|
|
args[i] = new char[str_size+1];
|
|
strncpy(args[i], qargs[i].toLocal8Bit().constData(),str_size);
|
|
args[i][str_size] = '\0';
|
|
}
|
|
|
|
execv(args[0],args);
|
|
Error(log, "error while restarting hyperion");
|
|
}
|
|
|
|
QByteArray command_exec(QString cmd, QByteArray data)
|
|
{
|
|
char buffer[128];
|
|
QString result;
|
|
|
|
std::shared_ptr<FILE> pipe(popen(cmd.toLocal8Bit().constData(), "r"), pclose);
|
|
if (pipe)
|
|
{
|
|
while (!feof(pipe.get()))
|
|
{
|
|
if (fgets(buffer, 128, pipe.get()) != NULL)
|
|
result += buffer;
|
|
}
|
|
}
|
|
return QSTRING_CSTR(result);
|
|
}
|
|
|
|
};
|
|
|
|
#endif
|