The objectives of this article are :
cmd.exe allows access to the Microsoft Windows Command Prompt, also known as Microsoft DOS.
To-date, cmd.exe is a 32-bit command prompt used in Windows NT, 2000, and XP and offers disk and file maintenance functions to your computer as well as network functions. cmd.exe can be found under System32 folder.
Capture the window by QTP
Typing to DOS window
Syntax: object.Type KeyboardInput.
KeyboardInput : A String value. The text string and/or constants representing non-alphanumeric keys.
Catching the Response
The GetVisibleText method returns the text from the specified area. The text to capture must be visible in the application window when the step runs. The area is defined by pairs of coordinates that designate two diagonally opposite corners of a rectangle.
Syntax : object.GetVisibleText ([Left], [Top], [Right], [Bottom])
The GetVisibleText method “catches” only the text that is visible. large commands with large responses are useless…
The WSript.Shell object provides functions to read system information and environment variables, work with the registry and manage shortcuts. You create a WSript.Shell object whenever you want to run a program locally, manipulate the contents of the registry, create a shortcut, or access a system folder.
you will see this detailed description if you are using PDM.DLL version 9
Runs an application in a child command-shell, providing access to the StdIn/StdOut/StdErr streams.
Syntax : object.Exec( strCommand )
strCommand : String value indicating the command line used to run the script. The command line should appear exactly as it would if you typed it at the command prompt.
What if your colleague installed MS-Windows on D: Drive? –> The C:WindowsSystem32cmd.exe will not work.
Executing a command
- /C– Carries out the command specified by string and then terminates.
- /K – Carries out the command specified by string but remains.
Executing the command
Provides status information about a script run with Exec along with access to the StdIn, StdOut, and StdErr streams.
Provides status information about a script run with the Exec() method.
- WshRunning ( = 0 )– The job is still running.
- WshFinished ( = 1 ) – The job has completed.
Returns the exit code set by a script or program run using the Exec() method. Executables set an exit code when they finish running. This conveys the status information when a process ends. Often, it is used to send an error code (or some other piece of information) back to the caller. If the process has not finished, the ExitCode property returns 0. The values returned from ExitCode depend on the application that was called.
The StdOut property contains a read-only copy of any information the script may have sent to the standard output.
- AtEndOfStream– Returns a Boolean value indicating whether the end of an input stream has been reached.
- ReadAll– Returns all characters from a stream.
- ReadLine – Reads an entire line from a stream.
Run the following code. why is the result empty?
since the “png” command has a syntax error ( ping ), the STDOUT remains empty.
Now, run the following code :
Since we have a syntax error, the STDERR buffer is filled, instead of the STDOUT. but, what about a “bad” command ( without syntax errors )?
in this case STDOUT will be filled, but not STDERR.
How could we know when an error occurred?
Print a list of “.exe” files under System32 without header information in lower case order by file name descending.