C# uygulamasından bir ant komut dosyasını aramaya çalışıyorum. Konsol penceresinin açılmasını ve kalmasını istiyorum (sadece komut istemini hemen arıyorum, fakat sonunda bir kar komutunu çağırmak istiyorum, bu da bir saat kadar sürebilir).Çağrı Komut İstemi ve Pencereyi Açın
public void ExecuteCommandSync(object command)
{
try
{
// create the ProcessStartInfo using "cmd" as the program to be run,
// and "/c " as the parameters.
// Incidentally, /c tells cmd that we want it to execute the command that follows,
// and then exit.
System.Diagnostics.ProcessStartInfo procStartInfo =
new System.Diagnostics.ProcessStartInfo("cmd", "/k " + command);
// The following commands are needed to redirect the standard output.
// This means that it will be redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = false;
// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
proc.WaitForExit();
}
catch (Exception objException)
{
Console.WriteLine(objException);
}
}
Ben de 5 parametrelere kadar geçmek istiyorum, ama şu anda pencere yeterince uzun açık tutmak sadece endişeleniyorum: Bu benim original gelen değişmiş kullanıyorum kodu vardır neler olduğunu görmek için, ve karınca komut dosyası tarafından oluşturulan herhangi bir içeriği okumakla ilgilenmiyorum. Kimsenin benim için çalışmamı istemesini istemiyorum, ama bir süredir bu konuda kafamı becermeye başladım, bu yüzden herhangi bir yardım çok takdir edilecek!
Bu işe yaradı! Bugünün çoğu için bununla sinirli oldum. Birden fazla komutla çalışmak için nasıl bir fikir? Özellikle beyaz boşluklu olanlar: cd c: \\ users \\ – Stubbs
Boşluklu komutlar, olduğu gibi doğru şekilde yorumlanmalıdır. Birden çok komut için; Komutları bir toplu iş dosyasına göndermeniz veya StandardInputStream'e komut göndermeye bakmanız gerekebilir, sadece bir dizede gönderebileceğiniz anlamına gelmez. –
Bunun gibi birden çok parametre de gönderebilirsiniz: [link] (http://stackoverflow.com/questions/5591382/how-to-execute-multiple-cammand-in-command-prompt-using-c-sharp). Bu, dizinleri değiştirir ve 4 parametreyi bir toplu iş dosyasına geçirir. Birisine yardımcı olabilir. – Stubbs