如何使用C#在命令提示符中执行多个命令

4
我想执行以下多个命令:
cd C:\Informatica\9.0\clients\PowerCenterClient\client\bin pmrep connect -r rs_01_lab -d Domain_DELLBANPDB01 -n etl_designer -x etl123
使用C#编写了以下代码:
        Process p = new Process();
        ProcessStartInfo info = new ProcessStartInfo("cmd.exe");
        info.RedirectStandardInput = true;
        info.UseShellExecute = false;

        p.StartInfo = info;
        p.Start();

        using (StreamWriter sw = p.StandardInput)
        {
                if (sw.BaseStream.CanWrite)
                {
                    sw.WriteLine("cd C:\Informatica\9.0\clients\PowerCenterClien\client\bin");
                    sw.WriteLine("pmrep");
                    sw.WriteLine("connect -r rs_01_lab -d Domain_DELLBANPDB01 -n etl_designer -x etl123");
                    StreamReader SR = p.StandardOutput;
                    string myString = SR.ReadToEnd();

                    sw.WriteLine("mypassword");
                    sw.WriteLine("use mydb;");
                }
        }

但我不会在命令提示符中编写命令。

能否请您帮助我解决这个问题。

先行致谢, Sunayana

2个回答

4
在MS-DOS中,您可以通过使用&符号来分隔命令,以在一行中执行多个命令。
String strCmdTxt = "/c cd C:\\Informatica\\9.0\\clients\\PowerCenterClient\\client\\bin & pmrep & connect -r rs_01_lab -d Domain_DELLBANPDB01 -n etl_designer -x etl123";
ProcessStartInfo i = new ProcessStartInfo("cmd.exe", strCmdTxt);
Process p = new Process();
p.StartInfo = i;
p.Start();

0

如果你不能将它作为参数发送,但它是必须键入程序的内容,那么你可能会遇到问题。就像telnet一样,你的“pmrep”应用程序可能不使用stdin。这里有一个类似问题的SO参考 - NKCSS

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接