我有一个批处理文件,当独立运行时,它会创建一个文件夹。但是,当我使用C#代码运行相同的批处理文件时,我什么都没有。我不确定如何调试。
我检查了批处理文件的路径。
C#代码
string startupPath = System.IO.Directory.GetCurrentDirectory();
string bat = startupPath+@"batch.bat";
var psi = new ProcessStartInfo();
psi.FileName = @"cmd.exe";
psi.Verb = "runas";
psi.Arguments = "/C " + bat;
Process.Start(psi);
批处理文件
@ECHO OFF
ECHO.
cd C:Usersrftx47DocumentsVisual Studio 2017ProjectsCertiHelperCertiHelper
mkdir folderA
ECHO.
PAUSE
CLS
EXIT
我缺少什么?
它正按照预期的方式进行操作,它正在运行命令控制台然后关闭它。确切的写作方式。我在下面为您重新分配了它。
string startupPath = System.IO.Directory.GetCurrentDirectory();
string bat = startupPath+@"batch.bat";;
var psi = new ProcessStartInfo();
psi.FileName = @bat; //this is where you need to put the file name.
psi.Verb = "runas";
psi.Arguments = "/c ";
psi.UseShellExecute = true; //this is where you start cmd
Process.Start(psi);