Forum Discussion

tim_faron's avatar
tim_faron
Contributor
12 years ago

Trouble getting dos command to execute as expected

I am trying to get the following command to run.




var Command = 'cmd /c wmic datafile where name="C:\\Program Files (x86)\\abc\\123\\abc efg\\aaa\\vv d e\\something.dll" get Version';

var oExecute = Sys.OleObject("WScript.Shell").Exec(Command);



When i paste it into the command window it's executing as i expect giving me 2 strings returned.. but via TestComplete 'Exec' it's running but the oExecute.ReturnCode is not zero and there are no results.



I have tried all different quote combinations but can seem to get it right.



Thanks


        

4 Replies


  • Hi Tim,



    aqFileSystem.GetFileInfo(fileName).VersionInfo is easier that shelling out to wmic.



    function Test()

    {

      var strFileName = "C:\\Windows\\notepad.exe";

      var oVerInfo = aqFileSystem.GetFileInfo(strFileName).VersionInfo;

      var strVersion =

        oVerInfo.FileMajorVersion + "." +

        oVerInfo.FileMinorVersion + "." +

        oVerInfo.FileBuildVersion + "." +

        oVerInfo.FileRevisionVersion;

      Log.Message(strVersion);

    }


  • nevermind i got it working .. it has to do with the \\ and making it \\\\ worked
  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Hi Tim,



    Try this:





    function TestWmicCommand()

    {

      var Command = 'cmd /c wmic datafile where name="C:\\Program Files (x86)\\abc\\123\\abc efg\\aaa\\vv d e\\something.dll" get Version';

      var oExecute = Sys.OleObject("WScript.Shell").Exec(Command);

     

      // Wait for command to end

      while(oExecute.Status == 0)

      {

        Delay(100);

      }



      if(oExecute.ExitCode == 0)

      {

         Log.Message(oExecute.StdOut.ReadAll());

      }

      else

      {

        Log.Error(oExecute.StdErr.ReadAll());

      }

    }





    Sincerely
  • Did you actually get this to work? I tried with Notepad and i get the following error listed below.



    var Command = 'cmd /c wmic datafile where name="C:\\Windows\\System32\\Notepad.exe" get Version';








    Node - WIN-73R0N5SIS5K


     


    ERROR:


     


    Description = Invalid query


     


    14:08:59 Normal Error



    -----------

    When i paste it into the cmd window however it works, so i assume i need some more quoting possibly