我要在C#里用语句调用一个.bat 文件,这个.bat 作用是调用一个应用程序
文件的内容是:
"c:\Program Files\Golden Software\Surfer8\Scripter\scripter.exe" -x jydzx.BAS
我的程序如下:
string strFilePath = Server.MapPath("\\WebApplication2\\Surfer\\b.bat");
try
{
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardError = true;
psi.Arguments=strFilePath;
psi.WorkingDirectory = Server.MapPath("\\WebApplication2\\Surfer\\");// Start the process
System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi);
// Open the batch file for reading
System.IO.StreamReader strm = System.IO.File.OpenText(strFilePath); // Attach the output for reading
System.IO.StreamReader sOut = proc.StandardOutput;// Attach the in for writing
System.IO.StreamWriter sIn = proc.StandardInput;
//Write each line of the batch file to standard input
while(strm.Peek() != -1)
{
sIn.WriteLine(strm.ReadLine());
}strm.Close();// Exit CMD.EXE
string stEchoFmt = "# {0} run successfully. Exiting";sIn.WriteLine(String.Format(stEchoFmt, strFilePath));
sIn.WriteLine("EXIT");// Close the process
proc.Close();// Read the sOut to a string.
string results = sOut.ReadToEnd().Trim();
// Close the io Streams;
sIn.Close();
sOut.Close();
}
catch(Exception ex )
{Response.Write( ex.ToString() ); }
可是运行之后,.bat 调用的程序c:\Program Files\Golden Software\Surfer8\Scripter\scripter.exe,在进程里没有路径,就运行不了,就卡在那里了。
哪位高人帮帮小女子的忙,谢谢。
以上的代码我市写在WebApplication里的,就出现上面的问题,但在WindowsApplication里就可以执行,是不是IE浏览器设置不对啊?
文件的内容是:
"c:\Program Files\Golden Software\Surfer8\Scripter\scripter.exe" -x jydzx.BAS
我的程序如下:
string strFilePath = Server.MapPath("\\WebApplication2\\Surfer\\b.bat");
try
{
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardError = true;
psi.Arguments=strFilePath;
psi.WorkingDirectory = Server.MapPath("\\WebApplication2\\Surfer\\");// Start the process
System.Diagnostics.Process proc = System.Diagnostics.Process.Start(psi);
// Open the batch file for reading
System.IO.StreamReader strm = System.IO.File.OpenText(strFilePath); // Attach the output for reading
System.IO.StreamReader sOut = proc.StandardOutput;// Attach the in for writing
System.IO.StreamWriter sIn = proc.StandardInput;
//Write each line of the batch file to standard input
while(strm.Peek() != -1)
{
sIn.WriteLine(strm.ReadLine());
}strm.Close();// Exit CMD.EXE
string stEchoFmt = "# {0} run successfully. Exiting";sIn.WriteLine(String.Format(stEchoFmt, strFilePath));
sIn.WriteLine("EXIT");// Close the process
proc.Close();// Read the sOut to a string.
string results = sOut.ReadToEnd().Trim();
// Close the io Streams;
sIn.Close();
sOut.Close();
}
catch(Exception ex )
{Response.Write( ex.ToString() ); }
可是运行之后,.bat 调用的程序c:\Program Files\Golden Software\Surfer8\Scripter\scripter.exe,在进程里没有路径,就运行不了,就卡在那里了。
哪位高人帮帮小女子的忙,谢谢。
以上的代码我市写在WebApplication里的,就出现上面的问题,但在WindowsApplication里就可以执行,是不是IE浏览器设置不对啊?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货