开发者

Javascript wshell.run not working properly

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


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");


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" ); 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜