开发者

how to execute multiple cammand in command prompt using c#

I want to execute multiple commands as below:

cd C:\Informatica开发者_JAVA百科\9.0\clients\PowerCenterClient\client\bin

pmrep

connect -r rs_01_lab -d Domain_DELLBANPDB01 -n etl_designer -x etl123

using C#...

And i have written a code as below:

        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;");
                }
        }

But i am not able to write the command in command prompt .

Can you please help me regarding this.

Thanks in advance, Sunayana


In MS-DOS you can execute multiple commands in one line by separating the commands with an ampersand (&).

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();


You need to set the parameter in the ProcessStartInfo.

Example.

Either set the Arguments Property

Or use a different overload of the .Start() method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜