-1

我需要使用来自 vb 脚本的参数调用 perl 脚本。如果参数中包含空格,则它不起作用。请帮忙。谢谢。

Set oShell = CreateObject("WScript.Shell")
sArgs = strArg1
sExec = "perl test.pl"
sCmd = sExec & " " & sArgs & " "
oShell.Run(sCmd)
4

1 回答 1

0

您可以通过将参数括在引号中来帮助 shell 标记您的命令。

直接在 shell 上运行,可能如下所示:

C:\> perl test.pl "C:/Path with spaces/foo.temp"

至于你如何在 VBScript 中做到这一点,我们可以通过两个步骤来解决这个问题:在 string 中转义文字引号,并使用 Replace() 来格式化该 string

sCmd = "perl test.pl ""{0}"""
sCmd = Replace(sCmd, "{0}", sArgs)
oShell.Run(sCmd)

这假设sArgs只包含一个参数;如果您要传递多个参数,则需要将每个参数单独括在引号中。

于 2013-08-22T20:57:24.447 回答