如何使用C#在命令提示符下执行多个cammand [英] how to execute multiple cammand in command prompt using c#
本文介绍了如何使用C#在命令提示符下执行多个cammand的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要执行多个命令如下:
I want to execute multiple commands as below:
CD C:\ Informatica的\ 9.0 \用户\ PowerCenterClient \客户端\ BIN
cd C:\Informatica\9.0\clients\PowerCenterClient\client\bin
pmrep
连接-r rs_01_lab -d Domain_DELLBANPDB01 -n etl_designer -x etl123
connect -r rs_01_lab -d Domain_DELLBANPDB01 -n etl_designer -x etl123
使用C#...
和我已经写了code如下:
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 .
能否请你帮我对此。
在此先感谢, Sunayana
Thanks in advance, Sunayana
推荐答案
在MS-DOS,你可以通过用符号隔开的命令(安培)在一行中执行多个命令。
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();
这篇关于如何使用C#在命令提示符下执行多个cammand的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文