Al-Mobarmge
Al-Mobarmge

Reputation: 31

How to Run Input Cmd Commands By VB.Net

I have a problem with CMD in a VB.NET project I'm making. How can I input three different commands to the same CMD window I open through a Button on my Form. Whenever I click the button on my form I want the CMD window to open, execute the first command and then automatically proceed to execute the next command and so on.

The three commands must be run in the same sequence in order to do its job.

The code I used:

Process.start ("cmd","/k First Code "  & "Second Code " & "Third Code")

Upvotes: 1

Views: 21087

Answers (2)

Al-Mobarmge
Al-Mobarmge

Reputation: 31

This is what I ended up using, thanks to the other answer

Process.start ( "cmd" , "/k First code second code -c Third Code " )

Upvotes: 1

Derek
Derek

Reputation: 8763

You could write out a batch file to disk and then run the batch file.

Also see: How to run two commands in one line in Windows CMD?

It looks like you can use & to separate commands.

I'd do something like:

Process.Start(String.Format("cmd /k {0} & {1} & {2}", "First Code", "Second Code", "Third Code"))

This might work better: (as an example)

Process.Start("cmd", String.Format("/k {0} & {1} & {2}", "dir c:", "dir /w c:", "pause"))

You can substitute your own commands in here.

Upvotes: 2

Related Questions