unity调用批处理方法和文本写入

调用批处理 

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

public class bichuli : MonoBehaviour
{
    private void Start()
    {
        buttonOnClick();
    }
    public void buttonOnClick()
    {
        ExecuteProgram("批处理文件名字", "路径", "参数");
    }

    static bool ExecuteProgram(string exeFilename, string workDir, string args)
    {
        System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
        info.FileName = exeFilename;
        info.WorkingDirectory = workDir;
        info.UseShellExecute = true;
        info.Arguments = args;
        info.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;

        System.Diagnostics.Process task = null;
        bool rt = true;
        try
        {
            Debug.Log("ExecuteProgram:" + args);

            task = System.Diagnostics.Process.Start(info);
            if (task != null)
            {
                task.WaitForExit(100000);
            }
            else
            {
                return false;
            }
        }
        catch (Exception e)
        {
            Debug.LogError("ExecuteProgram:" + e.ToString());
            return false;
        }
        finally
        {
            if (task != null && task.HasExited)
            {
                rt = (task.ExitCode == 0);
            }
        }

        return rt;
    }
}

文本写入

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public class krpanno : MonoBehaviour
{
    private static int linecount = 0;
    private static List<string> vtourconfig = new List<string>();

    private void Start()
    {
        PanoConfig();
        PI();
    }
    public static void PanoConfig()
    {
        using (StreamReader sr = new StreamReader("文本路径"))
        {
            //判断文件流是否读取完成
            while (sr.Peek() >= 0)
            {
                //将文本内容的每行存入链表中
                vtourconfig.Insert(linecount++, sr.ReadLine());
            }
        }
    }
    

    public void PI()
    {
        FileStream fs = null;
        //删除指示输出tilepath位置的内容,再添加重写添加想要输入的位置
        //此处知道其为链表第30个元素,不知道也可以exits/contains找出
        //也可以对其他内容进行修改
        vtourconfig.RemoveAt(31);
        vtourconfig.Insert(31, "tilepath=要设置的位置/panos/%BASENAME%.tiles/pano[_c].jpg");
        //创建一个新文件流,将链表中的内容写入到指定文本中
        //newconfigpath为配置文件存放的绝对路径加上配置文件名称,名称可以不设为vtour-normal.config,只要.bat调用时使用这个名称就行
        fs = new FileStream("C:/Users/sunqu/Desktop/Krpano/krpano-1.19-pr13/templates/vtour-normal.config", FileMode.Create);
        using (StreamWriter sw = new StreamWriter(fs))
        {
            for (int i = 0; i < linecount; i++)
            {
                sw.WriteLine(vtourconfig[i]);
            }
            //清理缓冲区,关闭并释放资源
            sw.Flush();
            sw.Close();
            fs.Close();
        }
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山竹炒大蒜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值