Unity3D Start external program and pass parameters

Before the development of the project, we have been using the shell model plus a subroutine, to initiate communication between the routines, and subroutines shell by shell, using the configuration file is completed.

I always feel so communication is very troublesome, because the shell configuration files needed to make changes and write, then the subroutine have to read the information. And when integrated, it will lead to a lot of configuration files, and need to do a lot of processing and route restrictions.

I found Process.Start () function, can pass parameters.

In other words, we can use Process.Start () function to start external programs, passing the communication parameters.

Specific operation is as follows:

public void StartEXE()
    {
        ProcessStartInfo processStartInfo = new ProcessStartInfo();
        processStartInfo.FileName = "C:/Users/Administrator/Desktop/Test/Demo.exe";
        processStartInfo.Arguments = "启动 程序 1 2  3";
        Process.Start(processStartInfo);
    }

Note that, if there are more parameters, need to be separated by spaces between the parameters.

Shell has passed parameters, then the subroutine parameters how to accept it? Specific operation is as follows:

private void Start()
    {
        string[] args = Environment.GetCommandLineArgs();
        text.text = args.Length.ToString();
        for (int i = 0; i < args.Length; i++)
        {
            text.text += "\n" + "Arg" + i + ":  " + args[i];
        }
    }

I have all the parameter information, print a Text above. FIG operating results as follows:

A very simple knowledge, there are packaged API can be used directly, here to record it, when you can forget the open look.

Guess you like

Origin www.cnblogs.com/xiaoyulong/p/10979367.html