Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过C#程序运行外部程序?_C# - Fatal编程技术网

如何通过C#程序运行外部程序?

如何通过C#程序运行外部程序?,c#,C#,如何通过C#程序运行记事本或计算器等外部程序?使用以下示例: // run notepad System.Diagnostics.Process.Start("notepad.exe"); //run calculator System.Diagnostics.Process.Start("calc.exe"); 按照米奇答案中的链接进行操作 您好,这是调用Notepad.exe的控制台应用程序示例,请检查此示例 using System; using System.Collections.

如何通过C#程序运行记事本或计算器等外部程序?

使用以下示例:

// run notepad
System.Diagnostics.Process.Start("notepad.exe");

//run calculator
System.Diagnostics.Process.Start("calc.exe");

按照米奇答案中的链接进行操作

您好,这是调用Notepad.exe的控制台应用程序示例,请检查此示例

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Demo_Console
{
    class Program
    {
        static void Main(string[] args)
        {
            Process ExternalProcess = new Process();
            ExternalProcess.StartInfo.FileName = "Notepad.exe";
            ExternalProcess.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
            ExternalProcess.Start();
            ExternalProcess.WaitForExit();
        }
    }
}
也许它会帮助你:

using(System.Diagnostics.Process pProcess = new System.Diagnostics.Process())
{
    pProcess.StartInfo.FileName = @"C:\Users\Vitor\ConsoleApplication1.exe";
    pProcess.StartInfo.Arguments = "olaa"; //argument
    pProcess.StartInfo.UseShellExecute = false;
    pProcess.StartInfo.RedirectStandardOutput = true;
    pProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    pProcess.StartInfo.CreateNoWindow = true; //not diplay a windows
    pProcess.Start();
    string output = pProcess.StandardOutput.ReadToEnd(); //The output result
    pProcess.WaitForExit();
}

欢迎来到堆栈溢出。我认为有把握认为英语是你的第二语言。为了增加你得到答案的机会,我将把问题标题改为“如何从C#程序打开外部程序?”。它也是一个控制台应用程序、Winforms、Web(希望不是)?请提供更多信息,并确保您查看堆栈溢出常见问题。@Michael我假设hw只是如何。仅供参考的“示例”的可能副本是一个死链接。在指定链接时总是有缺点。也许这只是我的视力下降,而不是因为它没有导致任何结果而死亡,而是因为它没有实际显示一个示例。请记住处置流程或在
使用(process pProcess=new process()){}
块中使用它