- Home /
Unity freezes while "procces redirect standardoutput"
im triying no make a GUI for a programm, but the problem is , that its work fine, when redirectoutput is false, but when i put it true, it freezes the unity until i close the process started manually, can someone help me?.
sorry my english, is not the best.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Diagnostics;
using System.IO;
using UnityEngine.UI;
public class JarLoader : MonoBehaviour
{
public bool started = false;
public bool started2 = false;
public string Console1;
public string path;
public string path2;
public string parameter;
private ProcessStartInfo p;
private Process process;
public string Console2;
private string autologin;
public bool DebugA;
public GameObject PaneLogeo;
public GameObject panelControl;
public InputField TwitchUsername;
public InputField TwitchOauth;
public Toggle SaveData;
public Toggle AutoLogIn;
public InputField CustomInput;
StreamReader errorReader;
StreamReader outputReader;
StreamWriter inputWriter;
private void Start()
{
using (StreamReader sr = new StreamReader(Application.dataPath + "\\FastLoginInfo.txt"))
{
TwitchUsername.text = sr.ReadLine();
TwitchOauth.text = sr.ReadLine();
autologin = sr.ReadLine();
if (autologin == "True")
{
Invoke("StartSystem",1f);
}
}
}
public void StartSystem()
{
if (SaveData)
{
using (StreamWriter sw = new StreamWriter(Application.dataPath + "\\FastLoginInfo.txt"))
{
sw.WriteLine(TwitchUsername.text);
sw.WriteLine(TwitchOauth.text);
sw.WriteLine(AutoLogIn);
sw.Close();
}
}
p = new ProcessStartInfo(path, parameter);
p.FileName = path;
p.Arguments = "-jar" + " " + path2;
p.UseShellExecute = false;
p.ErrorDialog = false;
p.RedirectStandardError = true;
p.RedirectStandardInput = true;
p.RedirectStandardOutput = true;
started = true;
Invoke("StartProcess", 1f);
}
public void StartProcess()
{
process = new Process();
process.StartInfo = p;
bool processStarted = process.Start();
inputWriter = process.StandardInput;
errorReader = process.StandardError;
outputReader = process.StandardOutput;
started2 = true;
InsertText();
}
private void Update()
{
Console1 = TwitchUsername.text;
Console2 = TwitchOauth.text;
if (!DebugA)
{
path = Application.dataPath + "/TwitchReader/runtime/jre-x64/bin/java.exe";
path2 = Application.dataPath + "/TwitchReader/TwitchIrcReader.jar";
} else if(DebugA)
{
path = @"C:\Program Files\Java\jre1.8.0_211\bin\javaw.exe";
path2 = Application.dataPath + "/TwitchReader/TwitchIrcReader.jar";
}
if (panelControl)
{
print(outputReader.ReadLine());
if (Input.GetKeyDown(KeyCode.Return))
{
SendCustomInput();
}
}
}
public void InsertText()
{
inputWriter.WriteLine(Console1);
inputWriter.WriteLine(Console2);
Invoke("StartControlMode",0.1f);
}
public void StartControlMode()
{
PaneLogeo.SetActive(false);
panelControl.SetActive(true);
}
public void ToggleJom()
{
inputWriter.WriteLine("ToggleJoin");
}
public void ToggleCom()
{
inputWriter.WriteLine("ToggleComment");
}
public void SendCustomInput()
{
inputWriter.WriteLine(CustomInput.text);
CustomInput.text = null;
}
}
Comment