当WCF服务运行批处理文件时,XCopy或MOVE不起作用.为什么?

Yau*_*sau 8 c# wcf iis-7 windows-services xcopy

我遇到过这样一种情况,即同一批处理文件的工作方式与命令行不同,以及何时从IIS上托管的WCF服务触发.区别在于XCOPY命令.当我正常运行批处理文件时,XCOPY会移动我需要的所有数据

XCOPY "C:\from" "C:\to" /K /R /E /I /S /C /H /G /X /Y
Run Code Online (Sandbox Code Playgroud)

但是当它从WCF服务运行时,没有任何东西被复制.从我的服务运行批处理我使用以下代码在C#中执行批处理文件 稍作修改.我的应用程序拉动在LocalSystem帐户下运行.我还尝试使用自己的帐户进行应用程序调查 - 不起作用.怎么了?

简短更新: 我最近学到的是我的WCF服务在App Pool用户下运行,但过程不是.为了实验,我在流程开始代码中进行了更新

var pwdArray = "mypassword".ToArray();
var pwd = new System.Security.SecureString();

Array.ForEach(pwdArray, pwd.AppendChar);
processInfo.UserName = "myuser";

processInfo.Password = pwd;
processInfo.Domain = "LocalMachine";
Run Code Online (Sandbox Code Playgroud)

但它没有帮助.似乎在描述的条件下运行XCOPY是神秘的.

还有一个更新: 在常规Windows服务下启动的进程中也发现了XCopy的相同问题.

Yau*_*sau 6

通过这篇文章管理解决我的问题(http://social.msdn.microsoft.com/Forums/vstudio/fr-FR/ab3c0cc7-83c2-4a86-9188-40588b7d1a52/processstart-of-xcopy-only-works-在调试器下?论坛= netfxbcl)所以答案实际上是:

这是xcopy.exe的怪癖.如果重定向输出,则还必须重定向输入.

        var command = "XCOPY ...."
        processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
        processInfo.CreateNoWindow = true;
        processInfo.UseShellExecute = true;
        // *** Redirect the output ***
        // unfortunately you cannot do it for X Copy

        //processInfo.RedirectStandardError = true;
        //processInfo.RedirectStandardOutput = true;


        process = Process.Start(processInfo);
        process.WaitForExit();
Run Code Online (Sandbox Code Playgroud)