Question by
CausticLasagne · Jun 20, 2016 at 06:21 PM ·
c#javathreadingcommand-line
Redirecting Standard IO on process on new thread
Hi all, I'm attempting the impossible.
So what I've got is a process that is running gradlew.jar with java and it works! The only issue is that when I go to execute the jar, my unity application hangs until the process is finished.
Currently I have it starting on a new thread, which doesn't hang, though now I need to redirect standard IO to my unity application.
Any Ideas?
Here's the code so far.....
void ExecuteCommand(string cmd)
{
string output = string.Empty;
string error = string.Empty;
installPath = GetJavaInstallationPath();
filePath = System.IO.Path.Combine(installPath, "bin/Java.exe");
Process p = new Process();
string classpath = Application.persistentDataPath + "/forge/gradle/wrapper/gradle-wrapper.jar";
UnityEngine.Debug.LogError("cpath:"+ filePath);
UnityEngine.Debug.LogError("fpath:" + classpath);
ProcessStartInfo info = new ProcessStartInfo(filePath,@"""-Dorg.gradle.appname=gradlew"" -classpath " + @"""" +classpath+ @"""" +" org.gradle.wrapper.GradleWrapperMain " + cmd);
info.RedirectStandardOutput = true;
info.RedirectStandardError = true;
info.RedirectStandardInput = true;
info.UseShellExecute = false;
info.WorkingDirectory = Application.persistentDataPath + "/forge";
info.CreateNoWindow = true;
p.StartInfo = info;
p.WaitForExit();
// Start a new thread, with the process created above
// It ignores my flags set above and I get an error in the console
ThreadStart ths = new ThreadStart(delegate () { p.Start(); });
using (StreamWriter sw = p.StandardInput)
{
if (sw.BaseStream.CanWrite)
{
//sw.WriteLine("pause");
//sw.WriteLine("cd " + Application.persistentDataPath + "/forge");
//sw.WriteLine("gradlew.bat - cleanCache - clean - setupDecompWorkspace--refresh - dependencies");
}
}
...
Comment