Click here to Skip to main content
15,907,906 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# code to triple a number Pin
J4amieC8-May-08 4:55
J4amieC8-May-08 4:55 
GeneralRe: C# code to triple a number Pin
BadKarma8-May-08 5:00
BadKarma8-May-08 5:00 
QuestionRe: C# code to triple a number Pin
CPallini8-May-08 3:20
mveCPallini8-May-08 3:20 
AnswerRe: C# code to triple a number Pin
Osten8-May-08 4:34
Osten8-May-08 4:34 
GeneralRe: C# code to triple a number Pin
laserbaronen8-May-08 4:36
laserbaronen8-May-08 4:36 
GeneralRe: C# code to triple a number Pin
Osten8-May-08 4:39
Osten8-May-08 4:39 
GeneralRe: C# code to triple a number Pin
laserbaronen8-May-08 4:41
laserbaronen8-May-08 4:41 
QuestionCMD.EXE from C# .net Pin
cristi_alonso8-May-08 1:34
cristi_alonso8-May-08 1:34 
I want to call cmd.exe from C# application and to change the directory from current directory.I have written code for this which is given below

------------------------------------------------------------------------------------------------------------------

//sample code //

using System;

using System.Collections.Generic;

using System.Text;

using System.Diagnostics;

using System.ComponentModel;

namespace Console_sample

{

class Program

{

public void OpenWithArguments()

{

ProcessStartInfo startInfo = new ProcessStartInfo("CMD.exe");

Process p = new Process();

startInfo.RedirectStandardInput = true;

startInfo.UseShellExecute = false;

startInfo.RedirectStandardOutput = true;

startInfo.RedirectStandardError = true;

p = Process.Start(startInfo);

p.StandardInput.WriteLine(@"Echo on");

p.StandardInput.WriteLine(@"dir " + @"C:");

p.StandardInput.WriteLine(@"chdir " + @"C:\WINDOWS ");

p.StandardInput.WriteLine(@"EXIT");

string output = p.StandardOutput.ReadToEnd();

string error = p.StandardError.ReadToEnd();

p.WaitForExit();

Console.Write(output);

p.Close();

Console.Read();

}

static void Main(string[] args)

{

Program myProcess = new Program();

myProcess.OpenWithArguments();


}

}

}

--------------------------------------------------------------------------------------

In the console I got following output

-----------------------------------------------------------------------------------------------------------

D:\Program\Console_sample\bin\Debug>Echo on

D:\Program\Console_sample\bin\Debug>dir C:
Volume in drive C has no label.
Volume Serial Number is F06C-447B

Directory of C:\Program Files\Microsoft Visual Studio 8\Common7\IDE

04/24/2008 05:17 PM <DIR> .
04/24/2008 05:17 PM <DIR> ..
03/26/2008 04:02 PM <DIR> 1033



D:\Program\Console_sample\bin\Debug>chdir C:\WINDOWS

D:\Program\Console_sample\bin\Debug>EXIT

---------------------------------------------------------------------------------

where my directory is not chaged while the DIR command got perfectly executed .How can i fix this ?Even i notice that when i write p.standardInput.writeline(@"date"); it doean't show me the date also.please provide solutuion for this .if anyone has sample code for executing cmd command from C# .net will be very useful.



any help appreciated

thanks in advance


AnswerRe: CMD.EXE from C# .net Pin
natsuyaki8-May-08 2:11
natsuyaki8-May-08 2:11 
QuestionmyProcess.StandardOutput Issue Pin
Harvey Saayman8-May-08 1:22
Harvey Saayman8-May-08 1:22 
AnswerRe: myProcess.StandardOutput Issue Pin
natsuyaki8-May-08 1:45
natsuyaki8-May-08 1:45 
QuestionPen Drive Pin
Bhim Prakash Singh8-May-08 0:53
Bhim Prakash Singh8-May-08 0:53 
AnswerRe: Pen Drive Pin
Christian Graus8-May-08 1:13
protectorChristian Graus8-May-08 1:13 
AnswerRe: Pen Drive Pin
Spunky Coder8-May-08 1:13
Spunky Coder8-May-08 1:13 
QuestionSending a E-mail in C# Pin
imnotso#8-May-08 0:21
imnotso#8-May-08 0:21 
AnswerRe: Sending a E-mail in C# Pin
N a v a n e e t h8-May-08 0:28
N a v a n e e t h8-May-08 0:28 
GeneralRe: Sending a E-mail in C# Pin
imnotso#8-May-08 0:47
imnotso#8-May-08 0:47 
GeneralRe: Sending a E-mail in C# Pin
imnotso#8-May-08 1:09
imnotso#8-May-08 1:09 
GeneralRe: Sending a E-mail in C# Pin
Christian Graus8-May-08 1:11
protectorChristian Graus8-May-08 1:11 
GeneralRe: Sending a E-mail in C# Pin
imnotso#8-May-08 1:43
imnotso#8-May-08 1:43 
GeneralRe: Sending a E-mail in C# Pin
Christian Graus8-May-08 1:48
protectorChristian Graus8-May-08 1:48 
GeneralRe: Sending a E-mail in C# Pin
imnotso#8-May-08 1:57
imnotso#8-May-08 1:57 
GeneralRe: Sending a E-mail in C# Pin
Christian Graus8-May-08 2:17
protectorChristian Graus8-May-08 2:17 
GeneralRe: Sending a E-mail in C# Pin
N a v a n e e t h8-May-08 2:59
N a v a n e e t h8-May-08 2:59 
GeneralRe: Sending a E-mail in C# Pin
imnotso#8-May-08 3:14
imnotso#8-May-08 3:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.