Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

How to run a real bash shell in-game ?

Discussion in 'Scripting' started by Lahms, Feb 11, 2019.

  1. Lahms

    Lahms

    Joined:
    Feb 11, 2019
    Posts:
    4
    Hi, sorry for the disturbing, I'm currently trying to create an in-game bash (which is linked to my unix system under the game). And I have to admit, that I'm a bit lost. Because I have to create a process using /bin/bash but also to get the output of commands..
    If you know a clean way to do that using the unity API, I would be REALLY grateful :) Thank you in advance !
     
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    1,294
    You can make a custom C++ plugin and communicate your functionality through it.
    Although, I haven't written one myself, so it's better to google on how to do it.

    But it's 100% possible for sure.

    Also, that's a weird game.
     
    Joe-Censored likes this.
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    6,175
    Using System.Diagnostics.Process you can start up /bin/bash on your unix machine.

    With it you can then set the 'StandardInput' and 'StandardOutput' to whatever StreamWriter and StreamReader you'd like of your choice.

    With this you can then intercept keyboard inputs and send them to the StandardInput for input purposes. And you can read the output from StandardOutput and display it on screen how ever you like.

    Then all you have to do is create a UI for it in game.
     
    Kurt-Dekker, ihgyug and Joe-Censored like this.
  4. Lahms

    Lahms

    Joined:
    Feb 11, 2019
    Posts:
    4
    Thank you so much for your quick answer, I will try to do it asap :)
    PS : it is a school game project, as my last project of my cybersecurity master degree I'm doing a security oriented RPG :p
     
  5. Lahms

    Lahms

    Joined:
    Feb 11, 2019
    Posts:
    4
    Hi again everybody, another day, another problem..
    After several try to do my own GUI, I just saw that you can directly use your terminal though unity.. Sadly impossible to get it work, seems that everybody have a terminal spawning, but all I get is an error.

    There is my code :
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using System.Diagnostics;
    5. using System.IO;
    6.  
    7. public class eniemetest : MonoBehaviour {
    8.  
    9.  
    10.     void test()
    11.     {
    12.         UnityEngine.Debug.Log("toto");
    13.         // This section of code is defining a shell and the directory where it should open in    
    14.             ProcessStartInfo startInfo = new ProcessStartInfo("/bin/bash");
    15.             startInfo.FileName = "/lib/terminfo/x/xterm-256color";
    16.         startInfo.WorkingDirectory = "/";
    17.             startInfo.UseShellExecute = false;
    18.             startInfo.RedirectStandardInput = true;
    19.             startInfo.RedirectStandardOutput = true;
    20.          startInfo.RedirectStandardError = true;
    21.  
    22.         //This starts the shell
    23.             Process process = new Process();
    24.             process.StartInfo = startInfo;
    25.             process.Start();
    26.      
    27.         process.StandardInput.WriteLine("mkdir /home/solal/test \r");
    28.         UnityEngine.Debug.Log("Text2");
    29.     }
    30.  
    31.     void Start()
    32.     {
    33.     UnityEngine.Debug.Log("Tttttttttttt");
    34.     test();
    35.     }
    36. }
    And there is the error, that I dont understand at all :



    I'm really sorry for asking that much help, but I feel a bit lost with the Unity API, it is usually easy to have a bash terminal in C x)

    Thank you in advance :)
     
  6. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    4,395
    Doesn't a Win32Exception means this is a Windows computer instead of *nix?
     
    xVergilx likes this.
  7. Lahms

    Lahms

    Joined:
    Feb 11, 2019
    Posts:
    4
    I'm on
    Linux version 4.13.0-46-generic (buildd@lcy01-amd64-002) (gcc version 7.2.0 (Ubuntu 7.2.0-8ubuntu3.2)) #51-Ubuntu SMP Tue Jun 12 12:36:29 UTC 2018

    and my unity is 2018.2.7f1
     
  8. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    6,175
    Win32Exception is just an exception type in the .net framework:
    https://docs.microsoft.com/en-us/do...tmodel.win32exception?view=netframework-4.7.2

    And if you check Process.Start can potentially throw it:
    https://docs.microsoft.com/en-us/do...mework-4.7.2#System_Diagnostics_Process_Start

    Even on *nix, the runtime/framework should behave the way it's documented. So if the framework is documented to throw an exception of type X under condition Y... then no matter the platform, it should throw exception X, even if its name is weird.

    So really, it's just that the class holds a name that reflects its historical roots rather than the actual platform it's on.
     
    Joe-Censored and xVergilx like this.
  9. eisenpony

    eisenpony

    Joined:
    May 8, 2015
    Posts:
    781
    What is the value of NativeErrorCode on your Win32Exception?
     
  10. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    4,395
    Thanks, I wasn't aware of that.