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 enigmatic · Dec 27, 2016 at 11:20 AM · serverfile-iocommand-linereading data

How to read the console values in Unity?

I am creating a windows application which will allow the user to upload the file and then access that file in unity application. Basically It's a window for selecting images presented on the screen and there is a option to upload your custom image as well. For uploading the custom image I am using a node script which will direct the user to a local webpage from where he/she can upload the value and the location of that image will be given the unity application for using it.

So far I have got to run the local node js server using bat file. But the issue not is the server returns the location of file which is given to console, how can I access that value which is returned into unity.

Here is the part of C# code that i am using to execute the bat file. ==> "node upload_server.js" is command for starting the local server for uploading the file.

 public void CreateBatchFile()
     {
         if (!System.IO.File.Exists (batFilePath)) {
             StreamWriter textSr = File.CreateText (batFilePath);
             textSr.WriteLine ("@Echo off");
             textSr.WriteLine ("echo \"starting local server\"");
             textSr.WriteLine ("cd c:\\users\\shubh\\Desktop\\MV_test\\upload-server\\");
             textSr.WriteLine ("node upload_server.js");
 
             textSr.Close ();
         } else {
             UnityEngine.Debug.Log ("bat file already exists");
         }
     }
 
     public void RunLocalServer()
     {
         try {
             Process myProcess = new Process();
             myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
             myProcess.StartInfo.CreateNoWindow = true;
             myProcess.StartInfo.UseShellExecute = false;
             myProcess.StartInfo.FileName = batFilePath;
 
             myProcess.EnableRaisingEvents = true;
             myProcess.Start();
             myProcess.WaitForExit();
             int uploadedFileLoc = myProcess.ExitCode;
             print(uploadedFileLoc);
         } catch (Exception e){
             print(e);        
         }
     }

alt text alt text

Please help!!

bg.png (103.0 kB)
bg1.png (8.4 kB)
Comment
Add comment · Show 1
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
avatar image enigmatic · Dec 27, 2016 at 11:24 AM 0
Share

Here is how it looks in command prompt.

alt text

bg2.png (10.1 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by enigmatic · Dec 27, 2016 at 12:32 PM

Yea! got it quickly. I'll post here my solution if anyone else may need it someday in future.

I just have to add the RedirectStandardOutput to true, then set enableRaisingEvent to true and finally read the output after the execution is finished by ReadToEnd() from standardOutput.

 myProcess.StartInfo.RedirectStandardOutput=true;
 myProcess.EnableRaisingEvents = true;
 myProcess.Start();
 
 //myProcess.BeginOutputReadLine();
 
 myProcess.WaitForExit();
 tempFilePath=myProcess.StandardOutput.ReadToEnd();



the tempfilepath will contains everything from your console output. :D

Comment
Add comment · Share
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

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

61 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

No graphics in build with -batchmode -nographics 2 Answers

What is the best approach to filter large data sets in Unity? 1 Answer

start unity standalone on server from php 0 Answers

Read and send data to Raspberry Pi 4 0 Answers

How do I know when file is done reading ? 1 Answer


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