Javascript wshell.run 无法正常工作

发布于 2024-10-08 21:39:33 字数 469 浏览 0 评论 0原文

我正在使用 HTA,其中我有一个函数应该使用 wshell.run 运行命令行,如果我在 Windows 'Run' util 中编写这一行,它工作正常,我希望它也能在 HTA 中工作使用 wshell.run。

该行是:

C:\xxxx\xxx\xxx.EXE aaa.psl abc

( 名称是 xxx 就在这里 - 不在真正的代码中..)

在我使用的 javascript 代码中:

function runCmd()
{
 wshShell.exec( "C:\xxxx\xxx\xxx.EXE aaa.psl abc" );
}

错误我xxx.EXE 应用程序中的 get 提示“无法打开 aaa.psl 文件未找到”。

谢谢, 罗特姆

I'm using HTA and in it I have a function that should run a command line with wshell.run , If I'm writing this line in Windows 'Run' util it is working fine, I want it to work also in the HTA with wshell.run.

The line is:

C:\xxxx\xxx\xxx.EXE aaa.psl abc

( The names are xxx just in here - not in the real code.. )

In the javascript code I'm using:

function runCmd()
{
 wshShell.exec( "C:\xxxx\xxx\xxx.EXE aaa.psl abc" );
}

The error I got is in the xxx.EXE application says "couldn't open aaa.psl File not found".

Thanks,
Rotem

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

季末如歌 2024-10-15 21:39:33

我很惊讶 xxx.EXE 程序竟然在运行。您需要在命令中转义这些反斜杠:

wshShell.Exec( "C:\\xxxx\\xxx\\xxx.EXE aaa.psl abc" );
//                ^-----^----^--- here

如果您在 aaa.psl 文件名中执行相同的操作,那就是您的问题。

如果您没有传递 aaa.psl 文件的完整路径,那么大多数程序(不是全部)都会期望它位于当前目录中,因此您'您需要确保您已正确设置当前目录(尽管使用绝对路径可能是更好的选择)。

例如,下面是告诉记事本编辑文件的示例:

shell = WScript.CreateObject("WScript.Shell");
shell.Exec("c:\\windows\\system32\\notepad.exe c:\\temp\\temp.txt");

...或通过当前目录:

shell = WScript.CreateObject("WScript.Shell");
shell.CurrentDirectory = "c:\\temp";
shell.Exec("c:\\windows\\system32\\notepad.exe temp.txt");

I'm surprised the xxx.EXE program is running at all. You need to escape those backslashes in the command:

wshShell.Exec( "C:\\xxxx\\xxx\\xxx.EXE aaa.psl abc" );
//                ^-----^----^--- here

If you're doing the same thing in the aaa.psl filename, that's your problem.

If you're not passing a full path to the aaa.psl file, then most programs (not all) will expect it to be in the current directory, so you'll want to make sure you've set the current directory correctly (although using absolute paths may be a better option).

Here's an example, for instance, of telling Notepad to edit a file:

shell = WScript.CreateObject("WScript.Shell");
shell.Exec("c:\\windows\\system32\\notepad.exe c:\\temp\\temp.txt");

...or via the current directory:

shell = WScript.CreateObject("WScript.Shell");
shell.CurrentDirectory = "c:\\temp";
shell.Exec("c:\\windows\\system32\\notepad.exe temp.txt");
七分※倦醒 2024-10-15 21:39:33

好吧 TJ 就是那个男人!! :)

我最终在你的帮助下通过替换 exec 来运行:

这是最终的(和工作的)代码:

function runCmd()
{
wshShell.CurrentDirectory = "G:\\xxx\\xxx";
wshShell.run( "xxx.EXE xxx.psl abc" ); 
}

Okkkk T.J. is the man!! :)

I finnaly made it with your help by replacing exec to run:

This is the final (and working) code:

function runCmd()
{
wshShell.CurrentDirectory = "G:\\xxx\\xxx";
wshShell.run( "xxx.EXE xxx.psl abc" ); 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文