我想执行以下多个命令:
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
答案 0 :(得分: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();
答案 1 :(得分:0)
您需要在ProcessStartInfo中设置参数。