unity 读取外部exe程序控制台信息

由于需要获取显卡信息,但是unity的自带函数,只能输出1个显卡

c#倒是可以但是引用了一个下载的dll   System.Management.dll

这个dll放到unity用不了,因为mono不支持

所以先用vs写个外部exe程序

using System;
using System.Management;

public class Sample
{
    public static void Main(string[] args)
    {
        string Gname = "";

        ManagementObjectSearcher objvide = new ManagementObjectSearcher("select * from Win32_VideoController");

        foreach (ManagementObject obj in objvide.Get())
        {
            Gname += ("Name - " + obj["Name"] + "</br>");
            //System.Console.WriteLine("Name - " + obj["Name"] + "</br>");
            //System.Console.WriteLine("DeviceID - " + obj["DeviceID"] + "</br>");
            //System.Console.WriteLine("AdapterRAM - " + obj["AdapterRAM"] + "</br>");
            //System.Console.WriteLine("AdapterDACType - " + obj["AdapterDACType"] + "</br>");
            //System.Console.WriteLine("Monochrome - " + obj["Monochrome"] + "</br>");
            //System.Console.WriteLine("InstalledDisplayDrivers - " + obj["InstalledDisplayDrivers"] + "</br>");
            //System.Console.WriteLine("DriverVersion - " + obj["DriverVersion"] + "</br>");
            //System.Console.WriteLine("VideoProcessor - " + obj["VideoProcessor"] + "</br>");
            //System.Console.WriteLine("VideoArchitecture - " + obj["VideoArchitecture"] + "</br>");
            //System.Console.WriteLine("VideoMemoryType - " + obj["VideoMemoryType"] + "</br>");

            //Console.WriteLine("=====================================================");
        }

        Console.WriteLine(Gname);
        Console.WriteLine("=====================================================");
        //Console.ReadKey();
    }
}

然后生成运行下

Unity代码

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;

public class GetSystemInfo : MonoBehaviour {

    string a = "";

    // Use this for initialization
    void Start () {

        //这种方法可以
        GetStr();

        //这种方法也可以
        //OpenEXE("C://Users/zts/source/repos/ConsoleApp9/ConsoleApp9/bin/Debug/ConsoleApp9.exe", "");
    }

    /// <summary>
    ///
    /// </summary>
    /// <param name="_exePathName">路径</param>
    /// <param name="_exeArgus">启动参数</param>
    public void OpenEXE(string _exePathName, string _exeArgus)
    {
        try
        {
            Process myprocess = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo(_exePathName, _exeArgus);
            myprocess.StartInfo = startInfo;
            myprocess.StartInfo.CreateNoWindow = true;
            myprocess.StartInfo.UseShellExecute = false;
            myprocess.StartInfo.RedirectStandardOutput = true;
            //myprocess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            myprocess.Start();
            a += myprocess.StandardOutput.ReadLine();//只能读取1行
            UnityEngine.Debug.Log(a);
            myprocess.WaitForExit();
        }
        catch (Exception ex)
        {
            UnityEngine.Debug.Log("出错原因:" + ex.Message);
        }
    }

    public void GetStr()
    {
        try
        {
            Process proc = new Process();
            proc.EnableRaisingEvents = false;
            proc.StartInfo.FileName = "C://Users/zts/source/repos/ConsoleApp9/ConsoleApp9/bin/Debug/ConsoleApp9.exe";
            proc.StartInfo.CreateNoWindow = true;
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.RedirectStandardOutput = true;
            //proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;//这句会让unity卡死
            proc.Start();
            string fingerprint = proc.StandardOutput.ReadLine();
            UnityEngine.Debug.Log(fingerprint);
            proc.WaitForExit();
        }
        catch (Exception)
        {

            throw;
        }

    }

    /********************************unity获取设备信息*******************************/
    string systemInfo;
    public void GetUnityInfo()
    {
        systemInfo = "\tTitle:当前系统基础信息:\n设备模型:" + SystemInfo.deviceModel + "\n设备名称:" + SystemInfo.deviceName + "\n设备类型:" + SystemInfo.deviceType +
            "\n设备唯一标识符:" + SystemInfo.deviceUniqueIdentifier + "\n显卡标识符:" + SystemInfo.graphicsDeviceID +
            "\n显卡设备名称:" + SystemInfo.graphicsDeviceName + "\n显卡厂商:" + SystemInfo.graphicsDeviceVendor +
            "\n显卡厂商ID:" + SystemInfo.graphicsDeviceVendorID + "\n显卡支持版本:" + SystemInfo.graphicsDeviceVersion +
            "\n显存(M):" + SystemInfo.graphicsMemorySize + "\n显卡像素填充率(百万像素/秒),-1未知填充率:" + SystemInfo.graphicsPixelFillrate +
            "\n显卡支持Shader层级:" + SystemInfo.graphicsShaderLevel + "\n支持最大图片尺寸:" + SystemInfo.maxTextureSize +
            "\nnpotSupport:" + SystemInfo.npotSupport + "\n操作系统:" + SystemInfo.operatingSystem +
            "\nCPU处理核数:" + SystemInfo.processorCount + "\nCPU类型:" + SystemInfo.processorType +
            "\nsupportedRenderTargetCount:" + SystemInfo.supportedRenderTargetCount + "\nsupports3DTextures:" + SystemInfo.supports3DTextures +
            "\nsupportsAccelerometer:" + SystemInfo.supportsAccelerometer + "\nsupportsComputeShaders:" + SystemInfo.supportsComputeShaders +
            "\nsupportsGyroscope:" + SystemInfo.supportsGyroscope + "\nsupportsImageEffects:" + SystemInfo.supportsImageEffects +
            "\nsupportsInstancing:" + SystemInfo.supportsInstancing + "\nsupportsLocationService:" + SystemInfo.supportsLocationService +
            "\nsupportsRenderTextures:" + SystemInfo.supportsRenderTextures + "\nsupportsRenderToCubemap:" + SystemInfo.supportsRenderToCubemap +
            "\nsupportsShadows:" + SystemInfo.supportsShadows + "\nsupportsSparseTextures:" + SystemInfo.supportsSparseTextures +
            "\nsupportsStencil:" + SystemInfo.supportsStencil + "\nsupportsVertexPrograms:" + SystemInfo.supportsVertexPrograms +
            "\nsupportsVibration:" + SystemInfo.supportsVibration + "\n内存大小:" + SystemInfo.systemMemorySize;
    }
    void OnGUI()
    {
        GUILayout.Label(systemInfo);
    }
    /************************************************************************/

    // Update is called once per frame
    void Update () {

    }
}

缺陷:这种读取只能读取控制台的1行数据,当然你可以把数据集中起来,一行输出

不知道有没有其他办法可以获取多行控制台信息

原文地址:https://www.cnblogs.com/sanyejun/p/9051613.html

时间: 2024-08-07 19:41:58

unity 读取外部exe程序控制台信息的相关文章

[实用工具]Unity调用外部EXE或Shell命令

版权所有,转载须注明出处!喜欢火影.喜欢Java.喜欢unity3D.喜欢游戏开发的都可以加入木叶村Q群:379076227 1.开门见山的需求有的时候,我们想把一些外部命令集成到unity中,比如,你想通过点击Unity中的一个按钮,就更新SVN(假设该项目是受SVN管理的).那么,就涉及到一个Unity调用外部可执行文件.bat/shell等.这个需求是挺常见的,也是不难实现的. 2.简单明了的实现我们先封装一个命令调用的函数: [C#] 纯文本查看 复制代码 ? 01 02 03 04 0

spring(读取外部数据库配置信息、基于注解管理bean、DI)

###解析外部配置文件在resources文件夹下,新建db.properties(和数据库连接相关的信息) driverClassName=com.mysql.jdbc.Driverurl=jdbc:mysql://localhost:3306/dbusername=rootpassword=root 开发步骤1)创建maven工程添加web.xml添加tomcat运行环境添加jar spring-webmvc,junit,commons-dbcp,mysql添加application.xml

windows下调用外部exe程序 SHELLEXECUTEINFO

本文主要介绍两种在windows下调用外部exe程序的方法: 1.使用SHELLEXECUTEINFO 和 ShellExecuteEx SHELLEXECUTEINFO 结构体的定义如下: 1 typedef struct _SHELLEXECUTEINFO { 2 DWORD cbSize; 3 ULONG fMask; 4 HWND hwnd; 5 LPCTSTR lpVerb; 6 LPCTSTR lpFile; 7 LPCTSTR lpParameters; 8 LPCTSTR lpD

细说Unity3D(一)——移动平台动态读取外部文件全解析

前言: 一直有个想法,就是把工作中遇到的坑通过自己的深挖,总结成一套相同问题的解决方案供各位同行拍砖探讨.眼瞅着2015年第一个工作日就要来到了,小匹夫也休息的差不多了,寻思着也该写点东西活动活动大脑和手指了.那么今天开始,小匹夫会记录一些平时工作中遇到的坑,以及小匹夫的应对方法,欢迎各位拍砖讨论.那么今天主要讨论一下Unity3D在移动端如何动态的读取外部文件,比如csv(txt),xml一类的文件.主要涉及的问题,就是PC端上本来测试的好好的东西,到了移动端就不能用了,所以要讨论一下PC端和

C#和asp.net执行外部EXE程序

这两天研究下.Net的执行外部EXE程序问题,就是在一个程序里通过按钮或其他操作运行起来另外一个程序,需要传入参数,如用户名.密码之类(实际上很类似单点登录,不过要简单的多的多):总结如下: 1.CS版:WebForm的调用外部程序,很简单 (1)如果不考虑参数问题,仅仅是执行另外一个程序,用:System.Diagnostics.Process.Start("')即可: 如:System.Diagnostics.Process.Start("D:\\首字母拼音码.exe",

Unity读取Excel文件(附源代码)

今天想弄个Unity读取Excel的功能的,发现网上有许多方法,采用其中一种方法:加入库文件 Excel.dll 和ICSharpCode.SharpZipLib.dll库文件,(还有System.Data.dll也要拷贝进来,在Unity安装路径C:\Program Files\Unity\Editor\Data\Mono\lib\mono\unity中),代码下载链接在最后. 使用时要注意1997-2003和2007版本的脚本不一样: 然后编写脚本DoExcel.cs: using Syst

慕容小匹夫 Unity3D移动平台动态读取外部文件全解析

Unity3D移动平台动态读取外部文件全解析 c#语言规范 阅读目录 前言: 假如我想在editor里动态读取文件 移动平台的资源路径问题 移动平台读取外部文件的方法 补充: 回到目录 前言: 一直有个想法,就是把工作中遇到的坑通过自己的深挖,总结成一套相同问题的解决方案供各位同行拍砖探讨.眼瞅着2015年第一个工作日就要来到了,小匹夫也休息的差不多了,寻思着也该写点东西活动活动大脑和手指了.那么今天开始,小匹夫会记录一些平时工作中遇到的坑,以及小匹夫的应对方法,欢迎各位拍砖讨论.那么今天主要讨

jar读取外部和内部配置文件的问题

最近修改XX应用的时候,涉及到需要在jar包中读取工程配置文件的问题.在jar包中,读取配置文件,需要单独处理. 项目中的一些配置文件,如dbconfig.properties log4j.xml 不想打包进jar. 因为可能会修改其中的一些配置信息,打包进jar,就变得比较笨拙,不方便修改文件. 可以用如下方式,实现在jar包中读取外部配置文件. 方法一: 关键代码. 读取properties文件方法: InputStream ins = getClass().getResourceAsStr

JAVA基础-输入输出:1.编写TextRw.java的Java应用程序,程序完成的功能是:首先向TextRw.txt中写入自己的学号和姓名,读取TextRw.txt中信息并将其显示在屏幕上。

1.编写TextRw.java的Java应用程序,程序完成的功能是:首先向TextRw.txt中写入自己的学号和姓名,读取TextRw.txt中信息并将其显示在屏幕上. package Test03; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOExceptio