简体   繁体   English

使用Javascript中的指定参数运行cmd.exe

[英]Run cmd.exe with specified parametrs from Javascript

Colls, I wrote a script which should: Colls,我编写了一个脚本,该脚本应:

  1. copy a file from C:\\PR\\DataFiles\\Input\\CL_CH5\\"+k+"\\ext_028042012.dat to C:\\PR\\DataFiles\\Input\\ext_028042012.dat - works fine 将文件从C:\\ PR \\ DataFiles \\ Input \\ CL_CH5 \\“ + k +” \\ ext_028042012.dat复制到C:\\ PR \\ DataFiles \\ Input \\ ext_028042012.dat-正常

  2. run cmd.exe with specified command line (p.3) 使用指定的命令行运行cmd.exe(p.3)

  3. after runing cmd.exe, script should go to c: disk, than change directory to c:/pr, then write in cmd line «process.bat c:\\pr ext_028042012.dat auto» and press Enter. 运行cmd.exe后,脚本应转到c:磁盘,然后将目录更改为c:/ pr,然后在cmd行“ process.bat c:\\ pr ext_028042012.dat auto»中写入并按Enter。

Code is : 代码是

 var fso = new ActiveXObject("Scripting.FileSystemObject");  
     for (var k = -2; k <= 0; k++)  
     {  
         var out_dir = "C:\\PROBE\\DataFiles\\Input\\CL_CH5";  
         // now i am copying a ext_028042012 to destination folder    
         fso.CopyFile("C:\\PR\\DataFiles\\Input\\CL_CH5\\"+k+"\\ext_028042012.dat",                                                                            
         "C:\\PR\\DataFiles\\Input\\ext_028042012.dat", 1);  
         WScript.Echo(k+"file copied.");  
         /*Block which run cmd window*/  
         //The following code should open a command window, changes to the path to C:\ ,   and executes the DIR command.
         var oShell = WScript.CreateObject ("WScript.Shell");  
         **oShell.run ("cmd /K cd c:\pr /K process.bat c:\ext_028042012.dat auto");**  
         WScript.Echo(k+ "file proceed!!!");
  1. Unfortunatly, it doesn't work. 不幸的是,它不起作用。 Script doesn't put command line from p.3 to opened cmd.exe window. 脚本不会将第3页的命令行放入打开的cmd.exe窗口。 Please, tell me where is my mistake. 请告诉我我的错误在哪里。 Thank you a lot. 非常感谢。

Your command string, 您的命令字符串,

"cmd /K cd c:\pr /K process.bat c:\ext_028042012.dat auto"

looks erroneous. 看起来是错误的。 I don't believe you can specify several /K commands like that - and since the meaning of /K is "Carry out the command and continue" never ending the first shell you launch. 我不相信您可以指定几个/K命令-而且/K的含义是“执行命令并继续”,所以永远不会结束您启动的第一个Shell。

Have you tried: 你有没有尝试过:

"cmd /K cd c:\pr && process.bat c:\ext_028042012.dat auto"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM