Running basic shell commands on Windows local machine fails

Hi all,

I’ve been agonizing over this for about a week now; please help.

My eggPlant script performs various automation steps to automate testing on Android. Many of the steps needed can be accomplished through adb shell commands, such as
[list]
installing APKs (I need to interact with multiple APKs)
pushing files to device
pulling files from device
performing various checks on specific files within device (such as file size etc)
[/list:u]
I used the adb shell commands as explained in http://docs.testplant.com/?q=content/adb-command-support

I tried the examples in the above link (customized of course) but they did not work.

In fact even basic shell commands such as the following don’t work:

set the shellCommand to ShellExecute
put shell("dir")

The above failed with exit code 2.

What is going wrong? Please help!

The main reason that you are having trouble is that the instructions you are referencing are based on running eggPlant on a Mac. The other problem that you’re having is that Windows is not a particularly command-line friendly operating system anyway, particularly when it comes to executing commands from a third-party tool like eggPlant.

You should still be able to use “shell” to run ADB commands, but you can’t get output directly back to the script. You’ll want to run shell as a command, not a function and you’ll need to redirect the output to a file and then read the file. So you’d modify the code to look like this:

shell "/path/to/adb/command" && MyCommand && "> adboutput.txt"
put file "adboutput.txt"

I’m sorry that you struggled with the sample code; we’re going to add a note that it assumes that you are running on a Mac and then in longer term wel’ll add a version for Windows.

Hi Matt,

I’m sorry but the code that you posted above didn’t work as it was. I had to make some significant modifications (as well as take help from TestPlant Support via a screenshare session) … and I’m still not at a point where my script is consistently producing results.

Here’s where I am:


to adb
	Params command

        -- SDK Path and device serial number are passed to every command;
        -- this step was suggested by Testplant support.
        -- (getConnectionInfo() is a simple function that extracts the device serial number.)

	put "D:\vish\adt-bundle\sdk\platform-tools" into sdkPath 
	put getConnectionInfo() into deviceSerialNo
	
        -- Delete any old outputs

	if (file "adbOutput.txt" exists)  then 
		log "deleting old adb log"
		wait 5
		delete file "adbOutput.txt"
	end if

        -- Construct Command

	set cmd to sdkPath && "/c" && <<adb>> && " & echo Done > adbOutput.txt"

        -- Execute!
	log "Executing command: " & cmd
	shell "C:\Windows\System32\cmd.exe", cmd	

        -- Wait until adbOutput contains any data
	put the seconds into startTime
	repeat until ((the size of file "adbOutput.txt" > 0) or ((the seconds) - startTime > 30)) 
		wait 5	
	end repeat
	
        -- return result
	put the result
	put file "adbOutput.txt" into retVal
	return retVal
end adb

I know; it’s messy. Where am I going wrong?

Hi Matt,

I’m sorry but the code that you posted above didn’t work as it was. I know it needed changes, but what I’m saying is that the syntax itself did not work on my machine.
I had to make some significant modifications (as well as take help from TestPlant Support via a screenshare session) … and I’m still not at a point where my script is consistently producing results.

Here’s where I am:


to adb
	Params command

        -- SDK Path and device serial number are passed to every command;
        -- this step was suggested by Testplant support.
        -- (getConnectionInfo() is a simple function that extracts the device serial number.)

	put "D:\vish\adt-bundle\sdk\platform-tools" into sdkPath 
	put getConnectionInfo() into deviceSerialNo
	
        -- Delete any old outputs

	if (file "adbOutput.txt" exists)  then 
		log "deleting old adb log"
		wait 5
		delete file "adbOutput.txt"
	end if

        -- Construct Command

	set cmd to sdkPath && "/c" && <<adb>> && " & echo Done > adbOutput.txt"

        -- Execute!
	log "Executing command: " & cmd
	shell "C:\Windows\System32\cmd.exe", cmd	

        -- Wait until adbOutput contains any data
	put the seconds into startTime
	repeat until ((the size of file "adbOutput.txt" > 0) or ((the seconds) - startTime > 30)) 
		wait 5	
	end repeat
	
        -- return result
	put the result
	put file "adbOutput.txt" into retVal
	return retVal
end adb

I know; it’s messy. Where am I going wrong?

You say that it’s not working, but you don’t say what it does or doesn’t do. Nothing jumps out at me just scanning the code, but if you explain where you are with it, it might help me know where to focus my attention.