This is the code for executing commands using asp.net
protected void btn_Click(object sender, EventArgs e)
{
ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe");
processStartInfo.RedirectStandardInput = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.UseShellExecute = false;
processStartInfo.RedirectStandardError = true;
Process process = Process.Start(processStartInfo);
if (process != null)
{
process.StandardInput.WriteLine("Cd\\");
//renaming a file
process.StandardInput.WriteLine("ren data.ofx abc1234.txt");
//creating directory
process.StandardInput.WriteLine("mkdir testDir");
//executing utility
process.StandardInput.WriteLine("bank2csv_pro.exe data.qbo output123.CSV");
process.StandardInput.Close();
// display the commands
// display the commands
string outputString = process.StandardOutput.ReadToEnd();
Response.Write(outputString);
// display the errors coming in execution
// display the errors coming in execution
string error = process.StandardError.ReadToEnd();
Response.Write(error);
}
}
No comments:
Post a Comment