命令提示符挂起

时间:2017-09-05 08:12:40

标签: c#

我制作了一个程序,用于备份Azure上的存储帐户。要做到这一点,我使用AzCopy。我的存储帐户中有4个容器,我通过我的存储帐户执行foreach以获取所有容器。我的第一个容器备份很好。备份完成后,我想移动到foreach命令提示符中挂起的下一个项目(容器)。不知道为什么会这样。

我的代码如下我的代码

public static string strCommand= @"C:\Program Files (x86)\Microsoft SDKs\Azure\AzCopy";

foreach (CloudBlobContainer items in sourcepslFileStoreContainers)
{
    containerCount = 0;
    if (items.Exists() && dayBlob.Exists())
    {
        // full backup using AzCopy
        if (dayBlob.Name == "day5" || dayBlob.Name == "day15")
        {
            var AzCopyProcess = new ProcessStartInfo()
            {
                FileName = "cmd.exe",
                RedirectStandardInput = true,
                RedirectStandardOutput = true,
                UseShellExecute = false,
                WindowStyle = ProcessWindowStyle.Normal
            };

            var process = new Process { StartInfo = AzCopyProcess };

            process.Start();
            process.StandardInput.WriteLine($@"cd {strCommand}");
            Console.WriteLine("Found directory");
            process.StandardInput.WriteLine($@"AzCopy.exe");
            Console.WriteLine("Found exe");
            process.StandardInput.WriteLine($"AzCopy /Source:{pslFileStore.Uri} /Dest:{dayBlob.Uri} /SourceKey:{pslFileStoreKey.ToString()} /DestKey:{pslFileStoreBackUpKey.ToString()} /S");
            //process.BeginOutputReadLine();
            process.StandardOutput.ReadToEnd();
            process.WaitForExit();
            process.Close();
            Console.WriteLine($"Backed up ");
        }
    }
}

0 个答案:

没有答案