Question Issues Running Command Prompt from Program - Help!

Hoho5000

Member
Joined
Oct 17, 2009
Messages
5
Programming Experience
1-3
I'm working on a program that relies on another program to convert some data. This other program is a command line executable. The code I'm using is as follows.

Code:
        Using m_process As New Process()
            With m_process.StartInfo
                .FileName = "cmd.exe"
                .UseShellExecute = False
                .RedirectStandardInput = True
                .CreateNoWindow = True
            End With

            m_process.Start()
            For Each file As FileInfo in folder
                 m_process.StandardInput.WriteLine("somecommand")
            Next

            m_process.Close()
        End Using
That should work, but the input to the command line never gets processed because as soon as the process is started, it ends. Setting to CreateNoWindow to false shows the command prompt opening for a split second and then closing, even though the operation should take at least several seconds. Scouring the internet reveals no clue as to why this is happening. If I set UseShellExecute to true, the window stays open, but I can't redirect input that way. This is really frustrating.

Can anyone offer some insight as to why this is happening?
 
Last edited:

gir489

Member
Joined
Oct 16, 2009
Messages
10
Programming Experience
1-3
Why don't you just use ShellExecute by itself? Why do you have to hook cmd?
 

Hoho5000

Member
Joined
Oct 17, 2009
Messages
5
Programming Experience
1-3
Because I need to run several commands within one window. That way, several hundred command prompts don't open at the same time and cause the system to hang.
 

gir489

Member
Joined
Oct 16, 2009
Messages
10
Programming Experience
1-3
This might help: [ame=http://www.vbforums.com/showthread.php?t=381405]Automate Command Prompt Window (CMD), Redirect Output to Application [2003/2005] - VBForums[/ame]
 
Top Bottom