Ranorex code which should run command through command prompt

Experiences, small talk, and other automation gossip.
navneet
Posts: 8
Joined: Tue Aug 03, 2021 12:50 pm

Ranorex code which should run command through command prompt

Post by navneet » Tue Nov 30, 2021 4:43 am

I need to write code module in ranorex which should open the command prompt and run a command inside command prompt.

For example :- To run the file located in the below location through command prompt. Users\Administrator\visualize.py
Can someone help me out.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Ranorex code which should run command through command prompt

Post by odklizec » Tue Nov 30, 2021 9:06 am

Hi,

You don't need to use code module for this. You should be able to run the py file by using Run action. Eventually, convert the Run action to user code and do whatever you want in code.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

navneet
Posts: 8
Joined: Tue Aug 03, 2021 12:50 pm

Re: Ranorex code which should run command through command prompt

Post by navneet » Tue Nov 30, 2021 2:33 pm

Hi ,

I am new to Ranorex.
Basically the intention here is I have few commands to be executed in the command prompt using Ranorex code.
The py file is just the example which I have given above but there are other huge lines of commands which I'm supposed to run through command prompt.
Below is the actual example which needs to be executed in command prompt using Ranorex code:

C:\Program Files\GEO\QC\GQC.exe" -N C:\Temp\Results\Cluster_Cluster01_2\20211123_121414

Can you help me with below queries:

1) How can we execute command in command prompt using Ranorex code. Could you help with me this.
2) Lastly, by the Run action, do you mean to use the Recording module and then convert it to the user code? If that is the case, I tried the recording module but unable to click on the command prompt option in the start menu using recording. Unable to click the cmd prompt while recording.

Fergal
Certified Professional
Certified Professional
Posts: 455
Joined: Tue Feb 18, 2014 2:14 pm
Location: Co Louth, Ireland
Contact:

Re: Ranorex code which should run command through command prompt

Post by Fergal » Thu Dec 02, 2021 11:44 am

navneet wrote:
Tue Nov 30, 2021 2:33 pm
...1) How can we execute command in command prompt using Ranorex code. ..
A recording module like this may work for you:
cmd.PNG
The XPath for the CMD Text Area is:

Code: Select all

/form[@title>'Administrator: C:\Windows']/text[@automationid='Text Area']
When the actions in the recording steps are merged and converted to usercode, they look like this:

Code: Select all

public void MergedUserCodeMethod(RepoItemInfo textInfo)
        {
            Report.Log(ReportLevel.Info, "Application", "Run application 'cmd.exe' in normal mode.");
            Host.Local.RunApplication("cmd.exe", "", "C:\\Windows\\system32", false);
            Report.Log(ReportLevel.Info, "Keyboard", "Key sequence 'cd..' with focus on 'textInfo'.", textInfo);
            textInfo.FindAdapter<Text>().PressKeys("cd..");
            Report.Log(ReportLevel.Info, "Keyboard", "Key sequence '{Return}' with focus on 'textInfo'.", textInfo);
            textInfo.FindAdapter<Text>().PressKeys("{Return}");
        }
You do not have the required permissions to view the files attached to this post.

navneet
Posts: 8
Joined: Tue Aug 03, 2021 12:50 pm

Re: Ranorex code which should run command through command prompt

Post by navneet » Mon Dec 06, 2021 10:34 am

Thank you