如何运行cmd.exe参数从javascript [英] How to Run cmd.exe with parameters from javascript

查看:267
本文介绍了如何运行cmd.exe参数从javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写javascript,应该运行cmd.exe与指定的命令行,就像这个文档。 google.com/file/d/0B7QHCoQDlEvKWUZSX3oxUDI2SDg/edit



我在微软网站上阅读shellexecute方法后准备代码:

  var objShell = new ActiveXObject(Shell.Application); 
objShell.ShellExecute(cmd.exe,C:cd C:\\pr main.exe blablafile.txt auto,C:\\WINDOWS\\ system32开放,1);

但不会在cmd.exe中插入命令行。



有人能帮助我吗?先谢谢你。

解决方案

也许您的计算机中没有安装(或注册)此ActiveX控件。



WScript.Shell 应在每个Windows中都可以找到:

  var run = new ActiveXObject('WSCRIPT.Shell')。Run(commands to run); 

如果中有空格要运行 ,您需要使用双引号。



编辑



主要来自MSDN: http:// msdn.microsoft.com/en-us/library/windows/desktop/gg537745(v=vs.85).aspx

  iRetVal = Shell.ShellExecute(
sFile,
[vArguments],
[vDirectory],
[vOperation],
[vShow]

让我们以 [vDirectory] ​​。文档说:包含由sFile指定的文件的目录的完全限定的路径。如果未指定此参数,则使用当前工作目录。

这意味着这个参数的路径无效(在它的末尾有 .cmd.exe )。创建ActiveX的所有示例都是这样:

  var objShell = new ActiveXObject(shell.application); 

请注意shell.application



和May12,谢谢你问这个。我之前不知道这个ActiveX控件,它似乎对我非常有用。



EDIT II



但你明白了吗?您的示例在我的应用程序完美:

  objShell.ShellExecute(cmd.exe,cd C:C:\ \ cd c:\\ext_file main.exe test.txt,C:\\WINDOWS\\ system32,open,1); 

有三个例外:



我在这个回答早期主要关于路径的一个。



2)转义 \ / p>

3)最后一个段是数字的类型,而不是字符串。


I am trying to write javascript which should run cmd.exe with a specified command line in it like this docs.google.com/file/d/0B7QHCoQDlEvKWUZSX3oxUDI2SDg/edit:

I prepare a code after reading shellexecute method on microsoft site:

var objShell = new ActiveXObject("Shell.Application");
        objShell.ShellExecute("cmd.exe", "C: cd C:\\pr main.exe blablafile.txt auto", "C:\\WINDOWS\\system32", "open", "1");

but it does not insert command line in cmd.exe.

Could anybody help me? Thank you in advance.

解决方案

Maybe you don't have this ActiveX-control installed (or registered) in your computer.

WScript.Shell should be found in every Windows:

var run=new ActiveXObject('WSCRIPT.Shell').Run("commands to run");

If there are spaces in commands to run, you need to use double quotes.

Edit

The content below is mainly from MSDN: http://msdn.microsoft.com/en-us/library/windows/desktop/gg537745(v=vs.85).aspx

iRetVal = Shell.ShellExecute(
  sFile,
  [ vArguments ],
  [ vDirectory ],
  [ vOperation ],
  [ vShow ]
)

Let's take [vDirectory]. The documentation says: "The fully qualified path of the directory that contains the file specified by sFile. If this parameter is not specified, the current working directory is used."

This means that you have an invalid path for this argument (having .cmd.exe at the end of it). Also all examples for creating the ActiveX are like this:

var objShell = new ActiveXObject("shell.application");

Notice the lowercase in "shell.application".

And May12, thank's for asking this. I didn't know about this ActiveX control before, it seems to be very usefull to me.

EDIT II

But have you understood it? Your example works perfect in my app:

objShell.ShellExecute("cmd.exe", "cd C: C:\\cd c:\\ext_file main.exe test.txt", "C:\\WINDOWS\\system32", "open", 1);

With three exeptions:

1) The one I maintioned early in this answer about the path

2) Escaped \ used also in arguments.

3) The last argment is type of number, not a string.

这篇关于如何运行cmd.exe参数从javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆