Reputation: 8044
My application was built on .NET Windows Forms
I have to convert the application to work as web application now.
Many fuctions have worked with no change what so ever
I used to have a function that executes command and opens command prompt window.
I put the code in ASP.net web application, the code is fine and commands get executed but the problem is that command prompt window does not show any more.
The code has not changed.
I wonder how can I get command prompt window appear in the server-side so admin can know if there is command error or any other issues?
This is the function that I use to execute a command
static void ExecuteCommand(string command, string workingFolder)
{
var processInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
processInfo.UseShellExecute = false;
processInfo.WorkingDirectory = workingFolder;
var process = Process.Start(processInfo);
process.WaitForExit();
}
Upvotes: 0
Views: 1145
Reputation: 1685
From the documentation
you can keep open the command window with "/K" flag
If the fileName parameter represents a command (.cmd) file, the arguments parameter must include either a "/c" or "/k" argument to specify whether the command window exits or remains after completion.
var processInfo = new ProcessStartInfo("cmd.exe", "/k " + command);
processInfo.WorkingDirectory = workingFolder;
var process = Process.Start(processInfo);
process.WaitForExit();
But in order to get the error and show it to your admin you have to use StandardError
and you can see the examples in the documentation.
Upvotes: 1