【问题标题】:Passing value with spaces as cmd parameter to programs将带有空格的值作为 cmd 参数传递给程序
【发布时间】:2014-02-21 03:38:41
【问题描述】:
strTarget = "C:\My Name\K.jpg"

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

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

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

如何解决这个问题?

【问题讨论】:

    标签: windows vbscript


    【解决方案1】:

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

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

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

    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
    

    【讨论】:

      猜你喜欢
      • 2010-10-03
      • 2017-05-07
      • 1970-01-01
      • 2016-04-08
      • 1970-01-01
      • 2017-09-04
      • 1970-01-01
      • 1970-01-01
      • 2019-11-13
      相关资源
      最近更新 更多