Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Kazkadez · May 15, 2017 at 05:13 AM · coroutineconsolecommand-lineprocesscommand line

Simultaneous Unity & Command Prompt?

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;
 }



Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Assertion Failed? 0 Answers

Windows command line returns 0 for compile errors in jenkins, 0 Answers

Class could not be found when executing method from command line (-executeMethod) 0 Answers

Get notification from command line or other application when a printer finish printng? 1 Answer

Choose screen with Command line arguments 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges