Z
Zeya
I am developing a ASP.Net(Web) based deployment tool, which requires
XCOPY functionality.
Here is the code for the method:
public static int ExecuteProcess ( string ProcessName, string
ProcessArguments )
{
string ErrorStream = "";
Process DOSProcess = new Process();
ProcessStartInfo StartInfo = new ProcessStartInfo();
StartInfo.FileName = @"CMD.exe ";
StartInfo.RedirectStandardError = false;
StartInfo.RedirectStandardOutput = false;
StartInfo.RedirectStandardInput = false;
StartInfo.UseShellExecute = false;
StartInfo.CreateNoWindow = true;
StartInfo.Arguments = @"/D /c " + ProcessName + " " +
ProcessArguments;
DOSProcess.EnableRaisingEvents = true;
DOSProcess.StartInfo = StartInfo;
DOSProcess.Start();
DOSProcess.WaitForExit( 15000 );
int ProcessExitCode = DOSProcess.ExitCode ;
if ( ProcessExitCode > 0 & !DOSProcess.HasExited )
DOSProcess.Kill();
DOSProcess.Dispose();
StartInfo = null;
return ProcessExitCode;
}
ExecuteProcess method takes ProcessName (in my case: XCOPY) and
ProcessArguments (in my case: the arguments needed for the XCOPY)
I stepped through to check the arguments assigned, I found:
/D /c XCOPY "E:\MySourcedirectory\Source\BUILDNUMBER\WebRoot"
"E:\MyDestinationDirectory\Destination\web" /S /E /F /H /R /Y /i
These are the switches I am passing for XCOPY: /S /E /F /H /R /Y /i
This runs excellent when I directly run from Command line as: cmd.exe
/D /c XCOPY "E:\MySourcedirectory\Source\BUILDNUMBER\WebRoot"
"E:\MyDestinationDirectory\Destination\web" /S /E /F /H /R /Y /i
The program first calls this method to back up existing files and then
copies the new files to the location. Back up works well but deployment
it does not do anything and returns exit code: 4.
According to MSDN, ExitCode 4 means: Initialization error occurred.
There is not enough memory or disk space, or you entered an invalid
drive name or invalid syntax on the command line.
As I mentioned, this runs smoothly from commandline.
When I use StandardError.ReadToEnd() it returns empty string.
Where am I going wrong? Any suggestions?
Thanks in advance.
XCOPY functionality.
Here is the code for the method:
public static int ExecuteProcess ( string ProcessName, string
ProcessArguments )
{
string ErrorStream = "";
Process DOSProcess = new Process();
ProcessStartInfo StartInfo = new ProcessStartInfo();
StartInfo.FileName = @"CMD.exe ";
StartInfo.RedirectStandardError = false;
StartInfo.RedirectStandardOutput = false;
StartInfo.RedirectStandardInput = false;
StartInfo.UseShellExecute = false;
StartInfo.CreateNoWindow = true;
StartInfo.Arguments = @"/D /c " + ProcessName + " " +
ProcessArguments;
DOSProcess.EnableRaisingEvents = true;
DOSProcess.StartInfo = StartInfo;
DOSProcess.Start();
DOSProcess.WaitForExit( 15000 );
int ProcessExitCode = DOSProcess.ExitCode ;
if ( ProcessExitCode > 0 & !DOSProcess.HasExited )
DOSProcess.Kill();
DOSProcess.Dispose();
StartInfo = null;
return ProcessExitCode;
}
ExecuteProcess method takes ProcessName (in my case: XCOPY) and
ProcessArguments (in my case: the arguments needed for the XCOPY)
I stepped through to check the arguments assigned, I found:
/D /c XCOPY "E:\MySourcedirectory\Source\BUILDNUMBER\WebRoot"
"E:\MyDestinationDirectory\Destination\web" /S /E /F /H /R /Y /i
These are the switches I am passing for XCOPY: /S /E /F /H /R /Y /i
This runs excellent when I directly run from Command line as: cmd.exe
/D /c XCOPY "E:\MySourcedirectory\Source\BUILDNUMBER\WebRoot"
"E:\MyDestinationDirectory\Destination\web" /S /E /F /H /R /Y /i
The program first calls this method to back up existing files and then
copies the new files to the location. Back up works well but deployment
it does not do anything and returns exit code: 4.
According to MSDN, ExitCode 4 means: Initialization error occurred.
There is not enough memory or disk space, or you entered an invalid
drive name or invalid syntax on the command line.
As I mentioned, this runs smoothly from commandline.
When I use StandardError.ReadToEnd() it returns empty string.
Where am I going wrong? Any suggestions?
Thanks in advance.