Forum Discussion

r_simms's avatar
r_simms
New Contributor
11 years ago

Running a Command Prompt command a passing result back to TestComplete

Our software can export documents and we need to validate that the expected exported document matches the actual exported document.



I found the best way for this is to use the following command via Command Prompt:



FC file1 file2



I have tried running the following command:



Call Sys.OleObject("WScript.Shell").Exec("cmd /k FC ""C:\\Users\\%USERNAME%\\Documents\\" & strFile & ".docx"" ""C:\\Users\\%USERNAME%\\Documents\\" & strFile & "2.docx""")



Regardless of how much tinkering I try, the command prompt will simply pop open and close before I can even see what has happened.



My ultimate goal is to take the result of this command to give it a pass or fail.



Any help is appreciated.



Also: Is there somewhere I can look up how to format forum posts?
  • Hi Richard,



    I recommend that you use the Word file comparison extension instead.



    But if you prefer fc, you can get its exit code and output like this (note single backslashes in paths):



    Sub Test

      Dim oShell, oExec

      Set oShell = Sys.OleObject("WScript.Shell")

      Set oExec = oShell.Exec("fc ""C:\Users\%USERNAME%\Documents\" & strFile & _

                               ".docx"" ""C:\Users\%USERNAME%\Documents\" & strFile & "2.docx""")



      Do While oExec.Status = 0

        Delay 100

      Loop



      If oExec.ExitCode = 0 Then

        Call Log.Checkpoint("The files are the same.")

      Else

        Call Log.Error("The files are different. See Additional Information.", oExec.StdOut.ReadAll)

      End If

    End Sub

  • r_simms's avatar
    r_simms
    New Contributor
    Hi everyone.



    Thanks for the replies.



    Unfortunately neither solutions worked for me. My machine uses Office 2013 so I could not verify if that plug in worked or not, and the command line snippet still has the same issue of opening and closing without being able to see a result.



    With the command line snippet, TestComplete will always say it fails regardless. Even if I use a ">> output.txt" to pipe the result to a text file to see an actual result, nothing gets created. I'm assuming this means something is going wrong somewhere.



    Is there a way for the command prompt to not close immediately? Like a "Pause"?



    Many thanks for the help so far.
  • Hi Richard,



    My machine uses Office 2013 so I could not verify if that plug in worked or not
    The WordDocs.Compare extension should work fine for Office 2013, too.



    and the command line snippet still has the same issue of opening and closing without being able to see a result.
    The example I posted dumps the fc output to the Additional Information panel in the test log. Here's an improved version that also dumps fc errors like "file not found". Can you try it and see what Additional Info says?



    strFile = ... ' Your strFile value



    Dim oShell, oExec

    Set oShell = Sys.OleObject("WScript.Shell")

    Set oExec = oShell.Exec("fc ""C:\Users\%USERNAME%\Documents\" & strFile & _

       ".docx"" ""C:\Users\%USERNAME%\Documents\" & strFile & "2.docx""")



    Do While oExec.Status = 0

      Delay 100

    Loop



    Select Case oExec.ExitCode

      Case 0: Log.Checkpoint "The files are the same.", oExec.StdOut.ReadAll

      Case 1: Log.Error "The files are different. See Additional Info.", oExec.StdOut.ReadAll

      Case Else: Log.Error oExec.StdErr.ReadAll

    End Select



    I'm assuming this means something is going wrong somewhere.
    Could file paths be wrong? What's the strFile value?