将带有空格的值作为 cmd 参数传递给程序 [英] Passing value with spaces as cmd parameter to programs

查看:35
本文介绍了将带有空格的值作为 cmd 参数传递给程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

strTarget = "C:\My Name\K.jpg"

如您所见,存储在 strTarget 中的地址中有一个空格,现在我正在尝试将其传递给应用程序,但它不起作用,因为地址中有空格 :(

as you can see there is a space in the address which is stored in strTarget, Now I\m trying to pass it to an application, but it won't work because there is space in address :(

TargetApp.Run """C:\My App\here.exe"" " & strTarget ,,true

如果我将 strTarget 更改为没有空间的 "C:\MyName\K.jpg" 它将起作用.

if I change strTarget into "C:\MyName\K.jpg" which does not have space it will work.

如何解决这个问题?

推荐答案

您需要在图像路径周围添加双引号,就像在可执行路径周围一样:

You need to add double quotes around the image path the same way you did around the executable path:

TargetApp.Run """C:\My App\here.exe"" """ & strTarget & """" ,,true

我通常建议为此使用引用函数,因为它会显着提高可读性:

I usually recommend using a quoting function for this, because it significantly increases the readability:

Function qq(str) : qq = Chr(34) & str & Chr(34) : End Function

app = "C:\My App\here.exe"
img = "C:\My Name\K.jpg"

TargetApp.Run qq(app) & " " & qq(img), 0, True

这篇关于将带有空格的值作为 cmd 参数传递给程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆