如何在C#Windows控制台应用程序中执行命令? [英] How to execute command in a C# Windows console app?

查看:71
本文介绍了如何在C#Windows控制台应用程序中执行命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C#Windows控制台应用程序中实现此伪代码?

How to implement this pseudo code in a C# Windows console app?

for i=1 to 100
    rename filei newFilei

主要目标是循环并执行Windows控制台应用程序中的任何cmd命令。 / p>

The key goal is to loop and execute any cmd command within a Windows console app.

class Program
{
    static void Main(string[] args)
    {
        string strCmdLine;
        System.Diagnostics.Process process1;
        process1 = new System.Diagnostics.Process();


        Int16 n = Convert.ToInt16(args[1]);
        int i;
        for (i = 1; i < n; i++)
        {
            strCmdLine = "/C xxxxx xxxx" + args[0] + i.ToString();
            System.Diagnostics.Process.Start("CMD.exe", strCmdLine);
            process1.Close();
        }


    }
}


推荐答案

Diagnostics.Process

            System.Diagnostics.Process proc;

            cmd = @"strCmdLine = "/C xxxxx xxxx" + args[0] + i.ToString();

            proc = new System.Diagnostics.Process();
            proc.EnableRaisingEvents = false;
            proc.StartInfo.FileName = "cmd";
            proc.StartInfo.Arguments = cmd;
            proc.Start();

这篇关于如何在C#Windows控制台应用程序中执行命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆