当WCF服务运行批处理文件时,XCopy或MOVE不起作用.为什么? [英] XCopy or MOVE do not work when a WCF Service runs a batch File. Why?

查看:160
本文介绍了当WCF服务运行批处理文件时,XCopy或MOVE不起作用.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当同一批处理文件的工作方式不同于命令行,并且是从IIS上托管的WCF服务启动时,我遇到了这种情况. 区别在于XCOPY命令. 当我正常运行批处理文件时,XCOPY会移动我需要的所有数据

I have faced a case when the same batch file works differently from command line and when it is fired from a WCF service hosted on IIS. The difference is in XCOPY command. when I am running the batch file normally than XCOPY moves all data I need

XCOPY "C:\from" "C:\to" /K /R /E /I /S /C /H /G /X /Y

,但是从WCF服务运行时,不会复制任何内容. 为了从服务中运行批处理,我正在使用以下代码在C#中执行批处理文件 还有一些小的修改. 我的应用程序请求在LocalSystem帐户下运行.我也尝试使用我自己的帐户进行应用程序调查-不起作用. 怎么了?

but when it runs from the WCF service nothing is copied. for running the batch from my service I am using the following code Executing Batch File in C# whith some little modifications. My Application pull is running under LocalSystem account. I also tryed to use my own account for the application poll - does not work. what is wrong?

最新更新: 我最近了解到,我的WCF服务正在应用程序池用户"下运行,但该过程并非如此.为了实验目的,我对流程开始代码进行了更新

Short update: What I have learned recently is that my WCF service is running under the App Pool User, but the process isn't. In purpose of experiment I have made an update in the process-start code

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

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

processInfo.Password = pwd;
processInfo.Domain = "LocalMachine";

但是没有帮助.在上述条件下运行XCOPY似乎有些神秘.

but it does not help. Seems there is a mystic in running XCOPY under described conditions.

又一次更新: 在正常Windows服务下启动的进程中,也发现了XCopy的相同问题.

One more update: The same problem with XCopy is also found in a process that starts under a regular windows service.

推荐答案

感谢这篇文章(

Managed to solve my poblem thanks to this post (http://social.msdn.microsoft.com/Forums/vstudio/fr-FR/ab3c0cc7-83c2-4a86-9188-40588b7d1a52/processstart-of-xcopy-only-works-under-the-debugger?forum=netfxbcl) so actually the answer is:

这是xcopy.exe的一个怪癖.如果您重定向输出,则必须 以及重定向输入.

This is a quirk of xcopy.exe. If you redirect the output, you have to redirect the input as well.

        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();

这篇关于当WCF服务运行批处理文件时,XCopy或MOVE不起作用.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆