TheCloud
TheCloud

Reputation: 11

Arguments and Command Prompt

So, What I'm trying to do is make command prompt open on button press with set perimeters. This is what I have so far:

Public ReadOnly Property TheIP() As String
    Get

        Return TextBox1.Text

    End Get
End Property

Process.Start("cmd", String.Format("/k {0} & {1} & {2}", "ping", TheIP, "-t", "-l"))

The problem I am having is "ping" and "-t" isn't getting executed properly.

I get the following message in command prompt:

'123.123.123.123' is not recognized as an internal or external command, operable program or batch file.

I also get

'-t' is not recognized as an internal or external command, operable program or batch file.

Upvotes: 1

Views: 455

Answers (1)

TessellatingHeckler
TessellatingHeckler

Reputation: 28993

What are the & doing in the string? That's a command prompt command to launch a new process.

e.g. dir & dir will run dir twice. So your string is running ping and then trying to run the IP as a command by itself.

Try:

Process.Start("cmd", String.Format("/k {0} {1} {2}", "ping", TheIP, "-t"))

(I took "-l" out because you don't have enough string formatting places to use it, and it needs parameters itself, anyway)

Or

Process.Start("cmd", String.Format("/k ping -t {0}", TheIP))

Upvotes: 2

Related Questions