Implement process starting on Linux platform
This commit is contained in:
@@ -468,7 +468,7 @@ int32 PlatformBase::StartProcess(const StringView& filename, const StringView& a
|
|||||||
|
|
||||||
int32 PlatformBase::RunProcess(const StringView& cmdLine, const StringView& workingDir, bool hiddenWindow)
|
int32 PlatformBase::RunProcess(const StringView& cmdLine, const StringView& workingDir, bool hiddenWindow)
|
||||||
{
|
{
|
||||||
return RunProcess(cmdLine, workingDir, Dictionary<String, String>(), hiddenWindow);
|
return Platform::RunProcess(cmdLine, workingDir, Dictionary<String, String>(), hiddenWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 PlatformBase::RunProcess(const StringView& cmdLine, const StringView& workingDir, const Dictionary<String, String>& environment, bool hiddenWindow)
|
int32 PlatformBase::RunProcess(const StringView& cmdLine, const StringView& workingDir, const Dictionary<String, String>& environment, bool hiddenWindow)
|
||||||
|
|||||||
@@ -2061,6 +2061,82 @@ bool LinuxPlatform::SetEnvironmentVariable(const String& name, const String& val
|
|||||||
return setenv(StringAsANSI<>(*name).Get(), StringAsANSI<>(*value).Get(), true) != 0;
|
return setenv(StringAsANSI<>(*name).Get(), StringAsANSI<>(*value).Get(), true) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32 LinuxPlatform::StartProcess(const StringView& filename, const StringView& args, const StringView& workingDir, bool hiddenWindow, bool waitForEnd)
|
||||||
|
{
|
||||||
|
String command(filename);
|
||||||
|
if (args.HasChars())
|
||||||
|
command += TEXT(" ") + String(args);
|
||||||
|
LOG(Info, "Command: {0}", command);
|
||||||
|
if (workingDir.HasChars())
|
||||||
|
{
|
||||||
|
LOG(Info, "Working directory: {0}", workingDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: support workingDir
|
||||||
|
// TODO: support hiddenWindow
|
||||||
|
// TODO: support waitForEnd
|
||||||
|
|
||||||
|
StringAnsi commandAnsi(command);
|
||||||
|
system(commandAnsi.GetText());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 LinuxPlatform::RunProcess(const StringView& cmdLine, const StringView& workingDir, bool hiddenWindow)
|
||||||
|
{
|
||||||
|
return RunProcess(cmdLine, workingDir, Dictionary<String, String>(), hiddenWindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 LinuxPlatform::RunProcess(const StringView& cmdLine, const StringView& workingDir, const Dictionary<String, String>& environment, bool hiddenWindow)
|
||||||
|
{
|
||||||
|
LOG(Info, "Command: {0}", cmdLine);
|
||||||
|
if (workingDir.HasChars())
|
||||||
|
{
|
||||||
|
LOG(Info, "Working directory: {0}", workingDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: support environment
|
||||||
|
// TODO: support hiddenWindow
|
||||||
|
|
||||||
|
String dir = GetWorkingDirectory();
|
||||||
|
StringAnsi cmdLineAnsi;
|
||||||
|
if (workingDir.HasChars())
|
||||||
|
{
|
||||||
|
cmdLineAnsi += "chmod ";
|
||||||
|
cmdLineAnsi += StringAnsi(workingDir);
|
||||||
|
cmdLineAnsi += "; ";
|
||||||
|
}
|
||||||
|
cmdLineAnsi += StringAnsi(cmdLine);
|
||||||
|
|
||||||
|
FILE* pipe = popen(cmdLineAnsi.GetText(), "r");
|
||||||
|
if (!pipe)
|
||||||
|
{
|
||||||
|
LOG(Warning, "Cannot start process '{0}'", cmdLine);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char rawData[256];
|
||||||
|
StringAnsi pathAnsi;
|
||||||
|
Array<Char> logData;
|
||||||
|
while (fgets(rawData, sizeof(rawData), pipe) != NULL)
|
||||||
|
{
|
||||||
|
logData.Clear();
|
||||||
|
int32 rawDataLength = StringUtils::Length(rawData);
|
||||||
|
if (rawDataLength == 0)
|
||||||
|
continue;
|
||||||
|
if (rawData[rawDataLength - 1] == '\0')
|
||||||
|
rawDataLength--;
|
||||||
|
if (rawData[rawDataLength - 1] == '\n')
|
||||||
|
rawDataLength--;
|
||||||
|
logData.Resize(rawDataLength + 1);
|
||||||
|
StringUtils::ConvertANSI2UTF16(rawData, logData.Get(), rawDataLength);
|
||||||
|
logData.Last() = '\0';
|
||||||
|
Log::Logger::Write(LogType::Info, StringView(logData.Get(), rawDataLength));
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 result = pclose(pipe);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void* LinuxPlatform::LoadLibrary(const Char* filename)
|
void* LinuxPlatform::LoadLibrary(const Char* filename)
|
||||||
{
|
{
|
||||||
const StringAsANSI<> filenameANSI(filename);
|
const StringAsANSI<> filenameANSI(filename);
|
||||||
|
|||||||
@@ -130,6 +130,9 @@ public:
|
|||||||
static Window* CreateWindow(const CreateWindowSettings& settings);
|
static Window* CreateWindow(const CreateWindowSettings& settings);
|
||||||
static bool GetEnvironmentVariable(const String& name, String& value);
|
static bool GetEnvironmentVariable(const String& name, String& value);
|
||||||
static bool SetEnvironmentVariable(const String& name, const String& value);
|
static bool SetEnvironmentVariable(const String& name, const String& value);
|
||||||
|
static int32 StartProcess(const StringView& filename, const StringView& args, const StringView& workingDir, bool hiddenWindow = false, bool waitForEnd = false);
|
||||||
|
static int32 RunProcess(const StringView& cmdLine, const StringView& workingDir, bool hiddenWindow = true);
|
||||||
|
static int32 RunProcess(const StringView& cmdLine, const StringView& workingDir, const Dictionary<String, String>& environment, bool hiddenWindow = true);
|
||||||
static void* LoadLibrary(const Char* filename);
|
static void* LoadLibrary(const Char* filename);
|
||||||
static void FreeLibrary(void* handle);
|
static void FreeLibrary(void* handle);
|
||||||
static void* GetProcAddress(void* handle, const char* symbol);
|
static void* GetProcAddress(void* handle, const char* symbol);
|
||||||
|
|||||||
Reference in New Issue
Block a user