Cause -
User is attempting to execute an OS command from Vugen.
Solution - LoadRunner provides a documented function which enables the execution of an OS command from within a script. The following code demonstrates running a remote "ping" command on a LoadRunner Injector. Note that in this case the output of the command is being written to a file, which is then read and displayed as a message in the script logs.
The function used to call the command is "system(command)" where command is a character array containing the command to be executed.
Action()
{
char command[] = "ping xxx.xxx.xxx.xxx > c:\\temp\\ping.txt";
char line[1000], ch;
long file_stream;
char *filename = "c:\\temp\\ping.txt";
extern int errno;
{
char command[] = "ping xxx.xxx.xxx.xxx > c:\\temp\\ping.txt";
char line[1000], ch;
long file_stream;
char *filename = "c:\\temp\\ping.txt";
extern int errno;
lr_output_message("Sending command : %s ", command);
system(command);
if ((file_stream = fopen(filename, "r")) == NULL ) {
lr_error_message("Cannot open %s", filename);
return -1;
}
return -1;
}
/* Get the first 1000 chars from the file */
if (fread(line, sizeof(char), 1000, file_stream) == NULL)
lr_output_message("fread error" );
else
lr_output_message( "Command response is : \"%s\"", line);
else
lr_output_message( "Command response is : \"%s\"", line);
if (fclose(file_stream))
lr_error_message("Error closing file %s", filename);
lr_error_message("Error closing file %s", filename);
/* Delete the temporary file */
if (remove(filename) == 0)
lr_output_message("Removed temp file %s", filename);
else
lr_output_message("Unable to remove %s error %d", filename, errno);
lr_output_message("Removed temp file %s", filename);
else
lr_output_message("Unable to remove %s error %d", filename, errno);
return 0;
}
}
Post a Comment