Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Gurus*
Posted

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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

  • *Gurus*
Posted

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")

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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....

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...