简体   繁体   English

使用Process.Start()使用流程路径执行流程

[英]Executing a process with Process.Start() using the path of the process

I'm doing this: 我正在这样做:

public static void ExecProcess(String path, string filename)
{
    Process proc = new Process();
    proc.StartInfo.FileName = path + "nst.exe";
    proc.StartInfo.Arguments = filename;
    proc.StartInfo.UseShellExecute = false;
    proc.StartInfo.RedirectStandardError = true;
    proc.StartInfo.RedirectStandardOutput = true;

    proc.Start();
    proc.WaitForExit();
    var stringa = proc.StandardOutput.ReadToEnd();
    proc.Close();
}

The problem is my process is using the path of my C# application and not its path. 问题是我的进程正在使用C#应用程序的路径,而不是其路径。 So nst.exe is in C:\\Desktop but when I call it with the code above the execution path became C:\\\\Documents\\VisualStudio\\MyProject\\Debug\\ . 因此nst.exe位于C:\\Desktop但是当我使用执行路径上方的代码对其进行调用时,它成为C:\\\\Documents\\VisualStudio\\MyProject\\Debug\\

How can I execute the process in his path? 我该如何执行他的操作流程?

[EDIT] This is how I call the method: [编辑]这就是我所说的方法:

    public void EseguiOttimizzatore()
    {
        OttimizzatoreService.ExecProcess(@"C:\Users\Developer\Desktop\", _idPlanning.ToString() + ".dat");
    }

设置StartInfoWorkingDirectory属性:

proc.StartInfo.WorkingDirectory = @"C:\Users\Developer\Desktop\";

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

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