How can I send parameter to exe file ?

Ask general questions here.
rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

How can I send parameter to exe file ?

Post by rastek » Thu Aug 07, 2014 2:37 pm

Hi,

I am using psexec to run my ranorex exe files.

Can I send test case parameter using the exe file ? I mean just defining parameters in test case is enouugh ? If so how the psexec syntax should be ? Normaly I use the below code to run my exe file in a remote PC.

C:\psexec -i -s \\10.254.20.21 C:\mytest.exe /tc:TestCase1

or do I need to use some external variables call from inside the test ?

User avatar
Aracknid
Posts: 342
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: How can I send parameter to exe file ?

Post by Aracknid » Thu Aug 07, 2014 6:31 pm

Are you writing the scripts in vb .net or c# and compiling them as a console application? If so, you can just add code to your scripts (or framework) to handle parsing the console app's command line arguments. I've got about 5 or 6 command line options I've added support for to my framework, such as which browser to test against, whether to clear the cache, what server to run the script against (I've got a web app), whether to run in different modes (unique to my scripts), etc...

Then when running using PSEXEC you just have to put the thing in quotes. So if for example you wanted to pass in a browser to run against, something like this should work:

C:\psexec -i -s \\10.254.20.21 "C:\mytest.exe /b:ff" <-- /b = browser and ff = firefox

Edit: This is off the top of my head, so the syntax might be different, but it should be possible

rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Re: How can I send parameter to exe file ?

Post by rastek » Fri Aug 08, 2014 10:47 am

Thanks Aracknid you realy helped me, but for further assiastance can you provide me a little code fragment ?

I am writing the scripts in vb .net and I created my projects using Ranorex VB.NET Test Suite which is windows console application.
I am confused about these terms. Do I have to create and use console applicaiton for this purpose ??


-----------
if you are using browser than that means your test is window application , right ? and you use another console project in your solution in order to run tests ?


--------------------
And from codeproject I found that
For winforms, all you need to do is access Application object:
Collapse | Copy Code
For Each arg As String In My.Application.CommandLineArgs
Console.WriteLine(arg);
Next

what you say about this ?
-----------------------
There is an example solution designed in this way called VipTestLibrary project and I found in program.cs such as

if ( args[0].ToLower() == "-tc" )
{
switch (args[1].ToLower())
{

But that example is written in c# code and is for test case only. can you provide me some vb code example for this ? Please.

User avatar
Aracknid
Posts: 342
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: How can I send parameter to exe file ?

Post by Aracknid » Fri Aug 08, 2014 2:04 pm

I'm using vb.net as well, but in Visual Studio using the Ranorex API. I don't use the Ranorex Studio or any of their development apps, except Spy. So I'm not sure about what you're talking about :D

Here is some sample code on using command line arguments in VB.NET:

http://www.vbdotnetforums.com/console-a ... eters.html

Hopefully this will help you get some understanding of what to do to get going on this.

Aracknid.

rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Re: How can I send parameter to exe file ?

Post by rastek » Fri Aug 08, 2014 2:37 pm

Thanks again Arackind. But I still have some questions in my mind.

In your first reply your wrote me

C:\psexec -i -s \\10.254.20.21 "C:\mytest.exe /b:ff" <-- /b = browser and ff = firefox

I wonder how you use this DOS-style parametrization in the code ?

I mean you write extra code to parse delimeter ? I mean you split parameters and if it is b then you use the parameter for browser, etc ?

Can you write me sample code how can I achive this ? I mean how to handle those arguments in your code.
It can be c# code in Visual Studio doesnt matter since we can also write any code in Ranorex Gui.

It will be greatful for me.

User avatar
Aracknid
Posts: 342
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: How can I send parameter to exe file ?

Post by Aracknid » Fri Aug 08, 2014 2:54 pm

Sorry I don't have the time to write the code for you. There are plenty of examples on the web. You just need to experiment and try things out.

But the style of "/b:ff" is my own style. You are just passing in strings to the program. It will break it up into an array for you. For example if I pass in /b:ff /f:test.xml, I would have an array of 2 items. Item 1 would be /b:ff and item 2 would be /f:file.xml.

You just need to iterate through the array, looking at the strings, and then analyze them to your needs. In my loop I'd look for the ":" and then grab the left side and right side. If the left side is /b, then I know I want to set my browser variable to something, and then I look at ff and know it's FireFox. Of course you also need error checking, in case you pass in incorrectly formatted arguments.

Or make your own style. Maybe you only need to pass 1 thing, like a file name. So all you need to do is validate that the 1 item in the array of arguments is a valid file and then deal with it how ever you want.

Aracknid

rastek
Posts: 157
Joined: Wed Aug 06, 2014 12:00 pm

Re: How can I send parameter to exe file ?

Post by rastek » Mon Aug 11, 2014 11:54 am

Hi Aracknid ? Thanks again for the reply.

Can you tell me at least where to take those inputs ?

Normaly Ranorex projects Main is as follows , cos returns errorcode (I also need that)

Function Main() As Integer

So you use Function man as integer or as string ?

Another point, you use just one projects (that means one exe) for input parameters ?

I mean can you handle them in just one project ?

Thanks.