如何使用变量建立Process.Start命令?
How to use a variable to build Process.Start command?
我正在尝试使用 Process.Start 通过 CMD 启动应用程序我目前使用:
Process.Start("cmd", "/k start C:\Windows\application.exe 127.0.0.1 8484")
但是我想取出目录并用这样的变量替换它:
Dim line As String = C:\Windows\Application.exe
Process.Start("cmd", "/k start *line* 127.0.0.1 8484")
Dim line As String = "C:\Windows\Application.exe"
Process.Start("cmd", "/k start " & line & " 127.0.0.1 8484")
根据 MSDN ,Process.Start()
将接受两个字符串参数,因此可以像 "/k start " & line & " 127.0.0.1 8484"
一样使用
Dim line As String = "C:\Windows\Application.exe"
Process.Start("cmd", "/k start """" """ & line & """ 127.0.0.1 8484")
为了安全起见,应用START "title" [/D path] [options] "command" [parameters]
语法模式:
- 如果
line
包含空白 space 字符,则用一对额外的双引号括起来,并且
- definitely use
"title"
:
Always include a title; this can be a simple string like
"My Script"
or just a pair of empty quotes ""
.
According to
the Microsoft documentation, the title is optional, but depending on
the other options chosen you can have problems if it is omitted.
根据 MSDN String Data Type (Visual Basic)
Format Requirements
You must enclose a String literal within quotation marks ("
"
). If you must include a quotation mark as one
of the characters in the string, you use two contiguous quotation
marks (""
)
我正在尝试使用 Process.Start 通过 CMD 启动应用程序我目前使用:
Process.Start("cmd", "/k start C:\Windows\application.exe 127.0.0.1 8484")
但是我想取出目录并用这样的变量替换它:
Dim line As String = C:\Windows\Application.exe
Process.Start("cmd", "/k start *line* 127.0.0.1 8484")
Dim line As String = "C:\Windows\Application.exe"
Process.Start("cmd", "/k start " & line & " 127.0.0.1 8484")
根据 MSDN ,Process.Start()
将接受两个字符串参数,因此可以像 "/k start " & line & " 127.0.0.1 8484"
Dim line As String = "C:\Windows\Application.exe"
Process.Start("cmd", "/k start """" """ & line & """ 127.0.0.1 8484")
为了安全起见,应用START "title" [/D path] [options] "command" [parameters]
语法模式:
- 如果
line
包含空白 space 字符,则用一对额外的双引号括起来,并且 - definitely use
"title"
:
Always include a title; this can be a simple string like
"My Script"
or just a pair of empty quotes""
.
According to the Microsoft documentation, the title is optional, but depending on the other options chosen you can have problems if it is omitted.
根据 MSDN String Data Type (Visual Basic)
Format Requirements
You must enclose a String literal within quotation marks ("
"
). If you must include a quotation mark as one of the characters in the string, you use two contiguous quotation marks (""
)