fadi Posted July 4, 2003 Posted July 4, 2003 Hello everybody, i wanted to ask how can i automate a commandline prompt. As an example, i want to be able to execute the command 'cd windows' or 'copy file1 file2' using vb.net rather than writing it directly. i know i can use the classes in IO namespace but i need to write dos commands exactly. thanks Quote
*Gurus* divil Posted July 4, 2003 *Gurus* Posted July 4, 2003 You can redirect the standard input and output of console applications (such as cmd.exe) when you start the process. Check out the RedirectStandardInput property of the ProcessStartInfo class. Once you have started a process with this property set to true, you can use myProcess.StandardInput.WriteLine("cd blah") etc to control it. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
fadi Posted July 7, 2003 Author Posted July 7, 2003 Hello, i tried to do what u said but i received the following error: " StandardIn has not been redirected." here is my code: Dim myProcessStartInfo As New System.Diagnostics.ProcessStartInfo() myProcessStartInfo.RedirectStandardInput = True Dim myProcess As New System.Diagnostics.Process() myProcess.StartInfo = myProcessStartInfo myProcess.Start("cmd") myProcess.StandardInput.WriteLine("cd windows") and the error is raised on the last line. thanks Quote
*Gurus* divil Posted July 7, 2003 *Gurus* Posted July 7, 2003 The following works for me: Dim ps As New ProcessStartInfo("cmd.exe") ps.RedirectStandardInput = True ps.UseShellExecute = False Dim process As Process = process.Start(ps) process.StandardInput.WriteLine("dir") Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
fadi Posted July 7, 2003 Author Posted July 7, 2003 fair enough,it works for me too. i needed not to show the command prompt at all but i managed to do that by setting the property CreateNoWindow to true. thanks alot anyways.... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.