file handling in LR

1,571 views
Skip to first unread message

aragonn

unread,
Dec 13, 2010, 8:06:46 AM12/13/10
to LoadRunner, gaurav....@capgemini.com
hi guys,
today , i was trying file handling in loadrunner.what I did is first
upload a file readme.txt in loadrunner.naw I want to write in this
file but it is not writing while just giving a path for that file on
local disk it was writing in that file .
now I am just confused what can be the possible issue for this thing .
somebody please help .

Thanks and regards
Gaurav mishra

James Pulley

unread,
Dec 13, 2010, 8:52:00 AM12/13/10
to lr-loa...@googlegroups.com
Please clarify: Are you looking for the file written to a particular
location at the end of a test or are you looking to specifically write a
file to disk using C file i/o functions?

James Pulley, http://www.loadrunnerbythehour.com/PricingMatrix

--
You received this message because you are subscribed to the Google
"LoadRunner" group.
To post to this group, send email to LR-Loa...@googlegroups.com
To unsubscribe from this group, send email to
LR-LoadRunne...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/LR-LoadRunner?hl=en

Anaz Mohamed

unread,
Dec 13, 2010, 9:11:58 AM12/13/10
to lr-loa...@googlegroups.com
Hi Gaurav


Below will help you 100 % this my script used in project


Action()
{
int fp,i,j;


//LPCSTR Rows;
char new_dir[] = "C:\\anaz";

//Create a directory under root called anaz and make it the current dir

if (mkdir(new_dir)==1)

{

lr_output_message ("Directory already created %s ", new_dir);

goto FILEOPEN;

return -1;

}

//Rows=lr_get_attrib_string("rows");

//j=atoi(Rows);

FILEOPEN:

//fp = fopen("c:\\anaz\\my_file{FileName}.csv","w+");
fp=fopen(lr_eval_string
("c:\\anaz\\my_file{FileName}.csv"), "w+");

if (fp==0)

{

lr_error_message ("Cannot open file, it is already opened %s", fp);

return -1;

}
fprintf(fp,"FirstName,LastName,Email,Salutation,title,street,City,State,Country,zip,phone,Department,Custom1,Custom2,Cost
Center\n");
for(i=0;i<=10;i++)
{

fprintf(fp,"%s",lr_eval_string("{FN},{SN},{FN}{SN}@may.com,{SAL},{Title},{Street},{City},{State},{Country},{ZIP},{Phone},DEV,cust1,cust2,cost1\n"));
}
fclose(fp);

//char fp= lr_eval_string("c:\\anaz\\my_file{FileName}.csv");

/*if (remove(lr_eval_string ("c:\\anaz\\my_file{FileName}.csv")) == 0)

lr_output_message (lr_eval_string("Removed new file
c:\\anaz\\my_file{FileName}.csv"));*/

//else

//lr_output_message ("Unable to remove the file %d error %d", fp);

/*if (rmdir(new_dir) == 0)

lr_output_message ("Removed new directory %s", new_dir);

else

lr_output_message ("Unable to remove %s error %d", new_dir);*/


return 0;
}

--
Regards,
Anaz

James Pulley

unread,
Dec 13, 2010, 9:38:29 AM12/13/10
to lr-loa...@googlegroups.com
Can you provide the error you are receiving and mark the line in question
with an asterisk?

Looking at your code I suspect you will have the following issues moving
forward

(1) When you get to the load generator your directory creation is in context
to the local disk of the load generator. You may run into issues with
directories you expect to me in place not being in place.
(2) If you don't properly manage your {Filename} parameter you will run into
lock situations where two threads/users attempt to obtain a lock against a
common resource for the purposes of file update. Be careful here to ensure
that your {Filename} is unique per virtual user or adjust your code to
include an explicit semaphore token to let vusers/threads know when it safe
to obtain an exclusive lock for writing.
(3) It is interesting that you are writing our a comma separated variable.
Traditionally when this occurs it is being done as expected input to another
virtual user. The problem with this model is that when a virtual user
starts it takes a copy of the parameter file and places it in RAM. From
this point forward no additional disk access is needed for the virtual user
to hit its parameters, but also no additional updates to the file will be
reflected in the data set used by the virtual user. HP recognized this
years ago and made available the virtual table server to address this
inter-user use of data where one business process depends upon the output of
another. What else does this imply, if you use the Seattle phone book as
your data source for random names and addresses, as was observed one time,
do not be surprised if your resource costs per virtual user are extremely
high on the RAM side. As an alternative to VTS there is also a solution
based upon MYSQL on the market. A couple of quick Google queries on 'MYSQL
VTS LoadRunner' should point you in the right direction.

Gaz Davidson

unread,
Dec 13, 2010, 9:43:07 AM12/13/10
to LR-Loa...@googlegroups.com, lr-loa...@googlegroups.com
Ugh... not only do you have a goto in your code, but it's also followed by an unreachable return.

You can't use multiple threads to write to a single file, not unless LoadRunner has some magic around their file IO. If you really *must* do this write to a separate file for each virtual user, and combine them at the end.

Gaurav Mishra

unread,
Dec 13, 2010, 11:19:32 AM12/13/10
to lr-loa...@googlegroups.com
@anaz : every thing is looking fine exept 1 thing ....... i need to run my script on performance centre but i can't give a filepath .so i need to upload that file in vugen itself.

so haw i can write in such a file. suppose I just upload readme.txt and I said file name as

char * filepath = "readme.txt"
so it should write in that file but it is not writing it . I am not getting any error. but it is not showing any thing .

@james : sir I suppose i have answered your question too.though writing directly on disk is quite ok I did that thing but for making my script compatible of PC I have to upload it in vugen.

James Pulley

unread,
Dec 13, 2010, 11:33:12 AM12/13/10
to lr-loa...@googlegroups.com

You are still not clear as to your end goal.   You can certainly include readme.txt as an extra file in your virtual user definition such that it will be uploaded to performance center and will also be distributed to your load generators as a part of the virtual user definition.

 

There is nothing so exotic about performance center as to cause you to develop your virtual users any differently.   In the end you have controllers and load generators as a part of the performance center architecture just as you have as  a part of the standard LoadRunner deployment model.   So long as you construct your virtual user in an environment neutral fashion, using best practices to limit external dependencies you should be fine.   What you seem to be confused about is where information is being written and what resources your virtual user can access and how.

 

James Pulley, http://www.loadrunnerbythehour.com/PricingMatrix

 

From: lr-loa...@googlegroups.com [mailto:lr-loa...@googlegroups.com] On Behalf Of Gaurav Mishra
Sent: Monday, December 13, 2010 11:20 AM
To: lr-loa...@googlegroups.com
Subject: Re: file handling in LR

 

@anaz : every thing is looking fine exept 1 thing ....... i need to run my script on performance centre but i can't give a filepath .so i need to upload that file in vugen itself.

--

Anaz Mohamed

unread,
Dec 13, 2010, 2:13:07 PM12/13/10
to lr-loa...@googlegroups.com
Guys come on grow up I can't cook everything here

This is a sample code

For your better understanding of the file operation functions. You
need fine tune it as per your own requirement

Gaurav

This script will run on performance center as on code it will create
folder in C drive in the name anaz (in load generator in which
actually script runs)

No worries it will deleted , In the mean time make note of parameter
names settings options threads etc......

Line is drawn just build your buildings

--
Regards,
Anaz

Reply all
Reply to author
Forward
0 new messages