Change the way to call the core in the speed test

pull/3107/head
2dust 2023-01-07 20:55:44 +08:00
parent fc54e19ce2
commit dd85ccd3f8
1 changed files with 12 additions and 5 deletions

View File

@ -228,15 +228,21 @@ namespace v2rayN.Handler
string fileName = CoreFindexe(coreInfo); string fileName = CoreFindexe(coreInfo);
if (fileName == "") return -1; if (fileName == "") return -1;
var pathTemp = Utils.GetConfigPath($"temp_{Utils.GetGUID(false)}.json");
File.WriteAllText(pathTemp, configStr);
if (!File.Exists(pathTemp))
{
return -1;
}
Process p = new Process Process p = new Process
{ {
StartInfo = new ProcessStartInfo StartInfo = new ProcessStartInfo
{ {
FileName = fileName, FileName = fileName,
Arguments = "-config stdin:", Arguments = $"-config \"{pathTemp}\"",
WorkingDirectory = Utils.GetConfigPath(), WorkingDirectory = Utils.GetConfigPath(),
UseShellExecute = false, UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true, RedirectStandardOutput = true,
RedirectStandardError = true, RedirectStandardError = true,
CreateNoWindow = true, CreateNoWindow = true,
@ -255,15 +261,16 @@ namespace v2rayN.Handler
p.Start(); p.Start();
p.BeginOutputReadLine(); p.BeginOutputReadLine();
p.StandardInput.Write(configStr);
p.StandardInput.Close();
if (p.WaitForExit(1000)) if (p.WaitForExit(1000))
{ {
throw new Exception(p.StandardError.ReadToEnd()); throw new Exception(p.StandardError.ReadToEnd());
} }
Global.processJob.AddProcess(p.Handle); Global.processJob.AddProcess(p.Handle);
Thread.Sleep(1000);
File.Delete(pathTemp);
return p.Id; return p.Id;
} }
catch (Exception ex) catch (Exception ex)