我有这样一部分代码:
Process proc = null;
try
{
proc = new Process();
string dir = HttpContext.Current.Server.MapPath("~/Other/");
proc.StartInfo.WorkingDirectory = dir;
p.StartInfo.FileName = "batch.bat";
p.StartInfo.CreateNoWindow = true;
p.Start();
p.WaitForExit();
}
catch (Exception e) { }只有当我将"dir“替换为
string.Format(@"C:\AbsolutePathHere")为什么?
编辑:代码在一个按钮中工作,单击事件处理程序。当它是一个预定的Quartz.NET作业时,它不起作用。当我有绝对的路径时,它总是起作用的。所以我的问题可能是:我如何让Quartz.NET和MapPath表现得很好?
发布于 2009-03-26 06:27:20
调用MapPath后的值或'dir‘是多少?抛出什么例外?工作进程可能没有执行batch.bat文件的权限。
没有更多的细节,很难给你一个明确的答案。
编辑您考虑过Quartz.NET没有访问HttpContext.Current的权限,因此MapPath不会解决这个问题吗?
Edit2是否可以使用AppDomain.CurrentDomain.BaseDirectory来确定您想要的路径,而不是~ (tilda)替换?我还看到了对System.Web.Hosting.HostingEnvironment.MapPath()的引用,您也可以尝试使用这些引用。
https://stackoverflow.com/questions/684705
复制相似问题