从C#Force运行批处理文件从文件目录运行?

lin*_*790 3 c# windows cmd batch-file

所以这是我的最终目标.Steam允许您将其他已安装的游戏添加到您的库中,但只有当它是一个.exe文件时才指向它开始运行.

我刚刚安装了Arena和Daggerfall,它们都是通过从.bat文件启动的DOSBox运行的.因此,我决定通过编写自己的.exe将其转换为.exe.到目前为止,我已经编写了代码.当我只运行.bat文件时,它打开一切正常,但是,当我尝试从我的代码运行它时,.bat文件执行但有错误.这是我的代码如下:

        if (File.Exists("D:\\Bethesda Softworks\\Arena\\Arena (Full Screen).bat"))
        {
            System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe", "/c" + "\"D:\\Bethesda Softworks\\Arena\\Arena (Full Screen).bat\"");
            psi.RedirectStandardOutput = true;
            psi.UseShellExecute = false;

            System.Diagnostics.Process proc;
            proc = System.Diagnostics.Process.Start(psi);
        }
Run Code Online (Sandbox Code Playgroud)

我得到的错误是这样的:"系统找不到指定的路径.'dosbox.exe'不被识别为内部或外部命令,可操作程序或批处理文件.

我不确定这是否是一个问题,因为如何从批处理文件中调用dosbox或.exe如何最终运行批处理文件.无论哪种方式,我宁愿在代码中修复它,而不是通过改变.bat文件本身.

任何帮助是极大的赞赏!!

Ale*_*exD 5

尝试设置ProcessStartInfo.WorkingDirectory

psi.WorkingDirectory = "D:\\Bethesda Softworks\\Arena";
Run Code Online (Sandbox Code Playgroud)