Quantcast
Channel: Questions in topic: "command line"
Viewing all articles
Browse latest Browse all 123

Simultaneous Unity & Command Prompt?

$
0
0
Hello, all. This is a bit complicated, but here's **what I'm trying to do:** 1. Run pronsole.exe (a command line interface for connecting and controlling to 3D Printers). 2. Have pronsole.exe run in the background to receive commands. 3. Read the output of those commands in Unity. **Here's what's happening:** When I go to playtest my program, pronsole opens. Unity hangs while pronsole is open. Once I close pronsole, the playtest begins and I see in my console some of the output from Pronsole redirected as it should be. At that point, it continues to try to read from pronsole, even though there's nothing to show. That returns as "" as I expect it to. **Here's what I need it to do for now:** I need it to open pronsole.exe and run without interrupting the Unity side of the program. **Here's what I've tried:** I've tried running it in a coroutine (where I'm currently at). I've tried it with compiler.waitForExit(); When I read the console for errors, nothing shows. I've tried using cmd.exe instead of pronsole.exe and the same issue occurs so I know it's not the CLI. **Notes:** "-e connect" is an argument to connect to the printer, which works. When I close pronsole and check the console in Unity, I can see all of the initialization script that shows if I were running pronsole standalone. Any help is appreciated. <3 **Here's my code:** Process compiler = new Process(); bool consoleStarted = false; bool consoleError = false; bool callForDisconnect = false; int refreshTimer = 0; int refreshRate = 15; // Use this for initialization void Start (){ StartCoroutine(startPronsole()); } IEnumerator startPronsole() { if (!consoleStarted && !consoleError) { try { compiler.StartInfo.FileName = "C:/PROGRA~1/Printrun-Win-Slic3r-03Feb2015/pronsole.exe"; compiler.StartInfo.Arguments = "/K -e connect"; compiler.StartInfo.UseShellExecute = false; compiler.StartInfo.RedirectStandardOutput = true; compiler.StartInfo.RedirectStandardError = true; compiler.StartInfo.RedirectStandardInput = true; compiler.Start(); consoleStarted = true; //compiler.WaitForExit(); } catch (Exception e) { consoleError = true; UnityEngine.Debug.Log(e); } } yield return null; } // Update is called once per frame void Update (){ if (consoleStarted && refreshTimer == 0) { StartCoroutine(readConsole()); } refreshTimer++; if (refreshTimer > refreshRate) { refreshTimer = 0; } } IEnumerator readConsole() { UnityEngine.Debug.Log("Reading output..."); string output = compiler.StandardOutput.ReadToEnd(); if (output != "") { UnityEngine.Debug.Log(output); } else { UnityEngine.Debug.Log("No Output to be shown."); } yield return null; }

Viewing all articles
Browse latest Browse all 123

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>