服务器端批量执行中的问题 [英] Issue in Batch execution at Server side
本文介绍了服务器端批量执行中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在服务器端执行批处理.此批处理将在服务器中创建一些文件.每当我运行以下代码时,我都不会获得创建文件的任何输出,并且在服务器中不会在命令窗口中打开更多内容.
Hi,
I have a requirement to execute a batch at server side. This batch creates some files in the server. When ever I am running the following code, I am not getting any output of created files and more over command window is not opened in server .
System.Diagnostics.Process myprocess = new System.Diagnostics.Process(); // Declare New Process
System.Diagnostics.ProcessStartInfo lObjProcInfo = new System.Diagnostics.ProcessStartInfo();
lObjProcInfo.UseShellExecute = false;
lObjProcInfo.RedirectStandardOutput = true;
lObjProcInfo.CreateNoWindow = true;
lObjProcInfo.RedirectStandardInput = true;
lObjProcInfo.WindowStyle = ProcessWindowStyle.Normal;
lObjProcInfo.CreateNoWindow = true;
lObjProcInfo.FileName = lStrBatchPath;
myprocess = System.Diagnostics.Process.Start(lObjProcInfo);
请帮忙.
谢谢
Sreenath
Please help out.
Thanks
Sreenath
推荐答案
这似乎是一个权限问题.由于安全原因,运行ASP.NET应用程序的默认帐户具有非常有限的权限,并且该帐户可能没有启动命令提示符的权限.
您将必须为该帐户分配必需的权限,或者使用具有必需权限的帐户开始该过程. Process.Start() [
It seems to be a permission issue. The default account under which ASP.NET application runs has very limited permissions due to security reasons and that account probably do not have permission to start a command prompt.
You will either have to assign required rights to that account or start the process using an account which has required permissions. Process.Start()[^] has an overload for that.
I would suggest Google for ASP.NET worker process permissions to know more about it.
Hope this helps!
我试图记录批处理文件运行的输出.注意,运行批处理文件后,它会直接设置为myprocess_Exited事件,而不会包含任何myprocess_OutputDataReceived或myprocess_ErrorDataReceived.
似乎在运行批处理时,实际上未执行批处理...但是在手动执行时批处理已在服务器上正确运行
任何帮助请在这里...
System.Diagnostics.ProcessStartInfo lObjProcInfo =新的System.Diagnostics.ProcessStartInfo();
lObjProcInfo.UseShellExecute = false;
lObjProcInfo.CreateNoWindow = true;
lObjProcInfo.RedirectStandardOutput = true;
lObjProcInfo.RedirectStandardInput = true;
lObjProcInfo.RedirectStandardError = true;
lObjProcInfo.WindowStyle = ProcessWindowStyle.Normal;
lObjProcInfo.FileName = lStrBatchPath;
System.Diagnostics.Process myprocess =新的System.Diagnostics.Process(); //声明新流程
myprocess.EnableRaisingEvents = true;
myprocess.OutputDataReceived + =新的System.Diagnostics.DataReceivedEventHandler(myprocess_OutputDataReceived);
myprocess.ErrorDataReceived + =新的DataReceivedEventHandler(myprocess_ErrorDataReceived);
myprocess.Exited + =新的EventHandler(myprocess_Exited);
myprocess.StartInfo = lObjProcInfo;
myprocess.Start();
myprocess.BeginOutputReadLine();
myprocess.BeginErrorReadLine();
myprocess.WaitForExit();
Hi,
I tried to log output of the batch file run. noticed that after running batch file it directly eneterd into myprocess_Exited event with out any myprocess_OutputDataReceived or myprocess_ErrorDataReceived.
It seems when running batch, actually batch is not been executed...but batch is running on server properly on manual execution
any help over here plzz....
System.Diagnostics.ProcessStartInfo lObjProcInfo = new System.Diagnostics.ProcessStartInfo();
lObjProcInfo.UseShellExecute = false;
lObjProcInfo.CreateNoWindow = true;
lObjProcInfo.RedirectStandardOutput = true;
lObjProcInfo.RedirectStandardInput = true;
lObjProcInfo.RedirectStandardError = true;
lObjProcInfo.WindowStyle = ProcessWindowStyle.Normal;
lObjProcInfo.FileName = lStrBatchPath;
System.Diagnostics.Process myprocess = new System.Diagnostics.Process(); // Declare New Process
myprocess.EnableRaisingEvents = true;
myprocess.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(myprocess_OutputDataReceived);
myprocess.ErrorDataReceived += new DataReceivedEventHandler(myprocess_ErrorDataReceived);
myprocess.Exited += new EventHandler(myprocess_Exited);
myprocess.StartInfo = lObjProcInfo;
myprocess.Start();
myprocess.BeginOutputReadLine();
myprocess.BeginErrorReadLine();
myprocess.WaitForExit();
-------------------------------------
public void myprocess_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
try
{
clsAppLogger.mFnLogError(clsAppLogger.enumLoggerType.INFORMATION, e.Data);
}
catch (Exception ex)
{
clsAppLogger.mFnLogError(clsAppLogger.enumLoggerType.ERROR, ex.Message.ToString());
}
}
public void myprocess_Exited(object sender, EventArgs e)
{
try
{
clsAppLogger.mFnLogError(clsAppLogger.enumLoggerType.INFORMATION, "Exited (Event) - Batch execution completed");
}
catch (Exception ex)
{
clsAppLogger.mFnLogError(clsAppLogger.enumLoggerType.ERROR, ex.Message.ToString());
}
}
public void myprocess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
try
{
clsAppLogger.mFnLogError(clsAppLogger.enumLoggerType.ERROR, e.Data);
}
catch (Exception ex)
{
clsAppLogger.mFnLogError(clsAppLogger.enumLoggerType.ERROR, ex.Message.ToString());
}
}
这篇关于服务器端批量执行中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文