0

Hi sirs/Madams
I am using vs2008, i have a problem. In my application command Prompt is open but file is not open through cmd. My requirement is any commands are not entered in cmd. Commands are written in code, but i don't know how to slove it.Just open the cmd after open the required file. Please suggest me ...

Thanks in advance..

4
Contributors
3
Replies
6
Views
4 Years
Discussion Span
Last Post by Doogledude123
0

I think this will work for you:

Imports System.IO
Module Module1

    Sub Main()
        'This sets up and starts the cmd window
        Dim MyApp As Process = New Process()
        MyApp.StartInfo.FileName = "cmd"
        MyApp.StartInfo.RedirectStandardInput = True
        MyApp.StartInfo.UseShellExecute = False
        MyApp.Start()
        'This sets up the cmd window to read your commands
        Dim MyInStream As StreamWriter = MyApp.StandardInput
        'send your commands like this.  Put any command that cmd will 
        'normally execute into a string and use MyInStream.WriteLine() method
        MyInStream.WriteLine("cd c:\")
        MyInStream.WriteLine("test.txt")
        'With this loop the app won't exit until you close the cmd window
        While Not MyApp.HasExited

        End While
    End Sub

End Module

Because the input is redirected, the cmd window won't accept any input from the keyboard, only from the code.

Edited by tinstaafl

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.