Hi,
I have some code that I want to use to run a command line utility and I want to be able to run it from an aspx page running under IIS. The command line utility is a local utility running on the same box as my IIS server, and the code works in Visual Studio, just not under IIS. Any suggestions?
The logs are totally silent on the issue. On line 36 (below), the log says:
"I read this from our process:" . . . .just blank after that.
Grrrr.....
I have some code that I want to use to run a command line utility and I want to be able to run it from an aspx page running under IIS. The command line utility is a local utility running on the same box as my IIS server, and the code works in Visual Studio, just not under IIS. Any suggestions?
The logs are totally silent on the issue. On line 36 (below), the log says:
"I read this from our process:" . . . .just blank after that.
Grrrr.....
Code:
public class CommandLineUtils : ICommandLineUtils
{
private static readonly ILog log = LogManager.GetLogger(typeof(CommandLineUtils));
private StringBuilder processStdOutput = null;
///
/// <summary>
/// Executes an Interwoven command line utility
/// </summary>
/// <param name="clt">The utility to execute</param>
/// <param name="args">Any arguments to pass on the command line</param>
/// <returns>The string of output, as produced by running the command</returns>
///
public string ExecIwovCLT(string clt, string args)
{
log.Debug("Executing command: '" + clt + " " + args + "'");
processStdOutput = new StringBuilder("");
Process proc = new Process();
proc.StartInfo.FileName = clt;
proc.StartInfo.Arguments = args;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
proc.ErrorDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);
try
{
proc.Start();
proc.BeginOutputReadLine();
proc.WaitForExit();
log.Debug("I read this from our process: \n" + processStdOutput.ToString());
}
catch (Win32Exception ex)
{
log.Error("Could not execute the '" + clt + " " + args + "' command");
log.Error(ex.ToString());
}
finally
{
proc.Close();
}
return processStdOutput.ToString();
}
///
/// <summary>
/// Event handler for process execution method (above)
/// </summary>
/// <param name="sendingProcess">process doing the outputting</param>
/// <param name="outLine">output line from the process</param>
///
private void proc_OutputDataReceived(object sendingProcess,
DataReceivedEventArgs outLine)
{
if (!String.IsNullOrEmpty(outLine.Data))
{
processStdOutput.Append(outLine.Data + Environment.NewLine);
}
}
}
}
Comment