I have a C# web application in which I want to execute Unix commands one by one. I want the command prompt window to appear and then after each command execution , move to the next command and then exit the window. I have tried the below, but the command prompt window does not appear and the commands are not getting executed after each wait
public void connecterOne()
{
try
{
using (Process p = new Process())
{
// set start info
p.StartInfo = new ProcessStartInfo("cmd.exe")
{
RedirectStandardInput = true,
RedirectStandardOutput = true,
UseShellExecute = false,
WorkingDirectory = @"c:\"
};
// event handlers for output & error
p.OutputDataReceived += p_OutputDataReceived;
p.ErrorDataReceived += p_ErrorDataReceived;
// start process
p.Start();
// send command to its input
p.StandardInput.Write("ftp server" + p.StandardInput.NewLine);
p.StandardInput.Write("username" + p.StandardInput.NewLine);
p.StandardInput.Write("pwd" + p.StandardInput.NewLine);
string output = p.StandardOutput.ReadToEnd();
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
static void p_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
Process p = sender as Process;
if (p == null)
return;
Console.WriteLine(e.Data);
}
static void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
Process p = sender as Process;
if (p == null)
return;
Console.WriteLine(e.Data);
}
How to execute commands one by one and have the command prompt window open which shows the commands being executed. I am not getting any errors, but there is no output seen.