Using vb.net Process Class to run a chunk of cmd line options

MrDeveloper
MrDeveloper used Ask the Experts™
on
How can I use the vb.net process class to run something like:

c:\whatever.exe <some arguments>
c:\whatever.exe <some arguments>
c:\whatever.exe <some arguments>
c:\whatever.exe <some arguments>
c:\whatever.exe <some arguments>
c:\whatever.exe <some arguments>
c:\whatever.exe <some arguments>

These all have CR returns at the end of ea line.  If I paste it into a cmd window, it executes fine.  I tried with this shell but some of them didn't execute properly.  Is there a way I can feed this to the process class to make it execute them all?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
The shell solution is probably the best approach for programs that have a GUI.  If they are just console applications, then opening one shell object for CMD.EXE and passing the commands as input seems like a good approach, provided you're not trying to do any redirection (">" for example)

The process class comes in handy when you're trying to do redirection.

One word of caution.... give the shell a few milliseconds to respond before you send the next command.  Don't just "blast 'em" to the CMD all at once.

So, tell us more about what you're trying to do.
why not use a batch  file?

 Sub Main()
        Dim p As New Process

        With p.StartInfo
            .UseShellExecute = True
            .FileName = "c:\15\test.bat"
            '.Arguments = OverallUpdate
        End With

        ' Execute the process and wait for it to exit
        If p.Start() Then
            p.WaitForExit()
        End If
    End Sub


in test.bat you have,
c:\whatever.exe <some arguments>
c:\whatever.exe <some arguments>
c:\whatever.exe <some arguments>
c:\whatever.exe <some arguments>
c:\whatever.exe <some arguments>
c:\whatever.exe <some arguments>
c:\whatever.exe <some arguments>

etc..

Commented:
I guess you are looking for this kind of samples. Is it right?

http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=2f601a7d-443e-4c09-b49e-68f64a18b8ad

Thanks,
Sachi
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Author

Commented:
Thanks to everyone for the help.  Yes, it certainly seems like the processes are interfering with one another when they are executed as a "bulk" process.  I've also tried using Shell and Process with the same effect.  You suggested that I try making it wait a few milliseconds between executions.  I'm going to play with that right now if I can figure out how to add a delay.  Any other suggestions would be appreciated!

(in case this is relevant, the command-line exe that is being fired modifies active directory user terminal service properties)

Author

Commented:
Thanks rolftollerud , I didn't do it EXACTLY like you did, but the batch file worked great.  In case anyone is interested (I doubt it), I ran into a slight glitch - the writeline puts a " at the beginning and end of ea line.  I got around it by concatenating the ascii BS character like:

WriteLine(1, Chr(10) & Update1 & Chr(10))

Thanks to everyone for all of the help, I really appreciate it

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial