Read data from Command Prompt

Mobile Testing, Android App Testing.
Posts: 72
Joined: Thu Oct 28, 2010 2:18 pm

Read data from Command Prompt

Post by Rakesh123 » Sun Jun 22, 2014 3:01 pm


I am doing automation testing for an android device.

So I want to read the device number from command prompt to a string variable in my script.

Command 'adb devices' will list all the devices connected but I am not sure how to pass this command from my script and retrive the device number in my script.

Can anyone guide me how to pass command in command prompt and read data from command prompt?


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

Re: Read data from Command Prompt

Post by odklizec » Mon Jun 23, 2014 8:19 am

If I understand you right, you want to use the list of devices provided by "adb devices" command to run test for each single device from that list? I don't think there is an easy/single-line solution of this problem.

What you need to do first is to save the list of devices to file. This should be the easiest part ;) You can try something like this:
adb devices > c:\output.txt
This should save the list of devices to output.txt file.

Now you need to parse the file to extract each single device ID and pass that ID to Ranorex command line. I think it would be too much work trying to achieve this from command line? I would personally use AutoIt to extract the device ID and pass it to Ranorex command line. But of course, you can use any scripting tool you want.
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