May12
May12

Reputation: 2520

Run cmd.exe with specified parametrs from Javascript

Colls, I wrote a script which should:

  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

  2. run cmd.exe with specified command line (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.

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. Please, tell me where is my mistake. Thank you a lot.

Upvotes: 0

Views: 2211

Answers (1)

Anders Lindahl
Anders Lindahl

Reputation: 42870

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.

Have you tried:

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

Upvotes: 1

Related Questions