ActiveXObject(“Shell.Application”) - 如何传递带空格的参数?
我使用 ActiveXObject 通过 JavaScript 从 asp.net 运行 exe。它运行成功,除了参数:
function CallEXE() {
var oShell = new ActiveXObject("Shell.Application");
var prog = "C:\\Users\\admin\\Desktop\\myCustom.exe";
oShell.ShellExecute(prog,"customer name fullname","","open","1");
}
例如,我传递了类似的参数,[1]客户名称,[2]全名,但在空格字符之后,Javascript感知到不同的参数。
我该如何修复?
I run exe from my asp.net with JavaScript using ActiveXObject. It runs successfully, except parameters:
function CallEXE() {
var oShell = new ActiveXObject("Shell.Application");
var prog = "C:\\Users\\admin\\Desktop\\myCustom.exe";
oShell.ShellExecute(prog,"customer name fullname","","open","1");
}
Example, I pass that like parameters,[1] customer name,[2] fullname, but after space character, Javascript perceive different parameter.
How can I fix?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ShellExecute
将第二个参数作为表示所有 参数的字符串,并使用正常的 shell 处理规则(特别是空格和引号)处理这些参数。在本例中,传递的 3 个参数是
customer
、name
、fullname
oShell.ShellExecute(prog,"customer 'a name with space' fullname",...)
正如 Remy Lebeau - TeamB 所更正/指出的那样,双引号可用于定义参数边界:
在本例中,3 个参数是通过的是
customer
,a name with paths
,fullname
也就是说,想想如何从命令提示符。使用
ShellExecute
时也是同样的情况。快乐编码。
ShellExecute
takes the 2nd parameter to be a string that represents all the arguments and processes these using normal shell processing rules: spaces and quotes, in particular.In this case the 3 parameters that are passed are
customer
,name
,fullname
oShell.ShellExecute(prog,"customer 'a name with spaces' fullname",...)
As corrected/noted by Remy Lebeau - TeamB, double-quotes can be used to defined argument boundaries:
In this case the 3 parameters that are passed are
customer
,a name with spaces
,fullname
That is, think of how you would call
myCustom.exe
from the command-prompt. It's the same thing when usingShellExecute
.Happy coding.
尝试用反斜杠转义空格。 cmd.exe
cd
命令执行此操作,也许您会很幸运,它也可以在这里工作...Try escaping your spaces with a backslash. The cmd.exe
cd
command does this, maybe you'll get lucky and it'll work here as well...