简体   繁体   English

C#运行批处理文件不起作用

[英]c# run batch file doen't work

I'm trying to exe batch file from C# console. 我正在尝试从C#控制台执行批处理文件。 The following code doesn't work. 以下代码不起作用。 I'd like to know what's wrong with my ProcessStartInfo configuration. 我想知道我的ProcessStartInfo配置出了什么问题。

String cmd = "/C "+ path2watch + "\\batch.bat";

ProcessStartInfo psi = new ProcessStartInfo() 
{
    CreateNoWindow = true,
    UseShellExecute = false,
    FileName = @"cmd.exe",
    Arguments = cmd,
    RedirectStandardError = true,
    RedirectStandardOutput = true,
    ErrorDialog = false
};

Process p = Process.Start(psi);
p.WaitForExit();

Cd doesn't work 镉不起作用

Thanks 谢谢

The problem what that I didn't set the working directory Property. 我没有设置工作目录属性的问题。 I've set the working directory to the wanted path. 我已经将工作目录设置为所需的路径。 But it's still strange why cd didn't overcome "the working directory" issue 但是,为什么cd不能克服“工作目录”问题仍然很奇怪

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM