[英]Execute CMD Command from vb.net
Hi I want to start a program from my vb.net app. 嗨,我想从我的vb.net应用程序启动程序。
The problem I have, are spaces in the commant. 我的问题是逗号中的空格。 My code looks like this :
我的代码如下所示:
Dim p As New Process
Dim pi As ProcessStartInfo = New ProcessStartInfo()
execute = generateStatement(project)
pi.FileName = "cmd.exe"
pi.UseShellExecute = False
pi.RedirectStandardOutput = True
pi.Arguments = "/K " + execute
p.StartInfo = pi
p.Start()
execute = "C:\\Program Files (x86)\\Microsoft Visual Studio\\VB98\\VB6.EXE" cmd Output = 'C:\\Program' is not reconized as internal or external command
execute =“ C:\\ Program Files(x86)\\ Microsoft Visual Studio \\ VB98 \\ VB6.EXE” cmd输出='C:\\ Program'未重新配置为内部或外部命令
then I tried to put Quotes ( add Char 34 ) befor and afer the string like this : 然后我尝试将引号(添加Char 34)放在befor之前,然后像这样处理字符串:
execute = ""C:\\Program Files (x86)\\Microsoft Visual Studio\\VB98\\VB6.EXE""
execute =“” C:\\ Program Files(x86)\\ Microsoft Visual Studio \\ VB98 \\ VB6.EXE“”
still same cmd output. 仍然相同的cmd输出。 So i tried the command via Shell, still same problem.
所以我通过外壳尝试了命令,仍然是同样的问题。
Can someone tell me how I can pass a consol command with spaces in it ? 有人可以告诉我如何传递带有空格的consol命令吗? Change dir is no option, I have to put some more directories in the command.
更改目录是没有选择的,我必须在命令中放置更多目录。
You are on the right track: To escape quote in the argument, you can use quotes. 您处于正确的轨道上:要在参数中转义引号,可以使用引号。 But, you must also put your escaped quoted string in a string so actually, you end up with three quotes where you define execute.
但是,还必须将转义的带引号的字符串放入字符串中,因此实际上,在定义execute的位置会得到三个引号。
execute = """C:\Program Files (x86)\Microsoft Visual Studio\VB98\VB6.EXE"""
quote 1: start string 引用1:开始字符串
quote 2: escape quote 报价2:转义报价
quote 3: the quote 报价3:报价
Or, escape it when you build pi.arguments: 或者,在构建pi.arguments时对其进行转义:
pi.Arguments = "/K " + """" + execute """"
quote 1: start string 引用1:开始字符串
quote 2: escape 引用2:逃脱
quote 3: the quote character 引用3:引用字符
quote 4: end string 引用4:结束字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.