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

Recommended Answers

All 3 Replies

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.

@tinstaafl If you understood that, you my friend, are a bloody genius. :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.