How to execute system commands in LoadRunner with the systems function

Source: Internet
Author: User

Premise: Windows system implementation function: Use the system function in LR to perform the function of the command: The C function is used to establish the file, write the file and read the file. Main related functions: Sprintf/fopen/fgetc/fread/fclose Action () {int count,total=0,i; char buffer[1000]; long file_stream; Char fil

Premise:Windows System

Implementation function: Execute system commands with the systems function in LR

Related functions: Use C functions in LR to create files, write files, read files.

Main correlation function: Sprintf/fopen/fgetc/fread/fclose

Action () {int count,total=0,i;      Char buffer[1000];     Long File_stream;     Char filename[1024], command[1024],line[100];     Char new_dir[] = "C:\\test"; if (mkdir (New_dir))LR_output_message ("Create directory%s failed", New_dir);     else           lr_output_message ("Created new directory%s", New_dir);     sprintf ( FileName, "%s\\%s", New_dir, "Newfile.txt");     sprintf (Command, "dir/b c:\\ >%s/w", filename );     System (Command);     lr_output_message ("Created new file%s", FileName);   if ((File_stream=fopen (filename, "R")) ==null)        {        lr_error_message ("Can not open%s", filename);        return-1;  }   for (i=1;i<10;i++)     {       if (Fgets (line, file_stream) = = NULL)           lr_output_message (" Fgets error ");     ELSE&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp;  Lr_output_message ("The first line was \"%s\ ", line);   }    while (!feof (file _stream))               {       Count=fread (buffer,sizeof (char), 1000,file_stream);       Lr_output_ Message ("%3d read", count);    if (ferror (file_stream))                {    lr_output_message ("Error reading file%s", filename);     break;       }   total+=count;        }      lr_output_message ("Total number of bytes read =%d", total);  & nbsp;   if (fclose (file_stream))       lr_error_message ("Error closing file%s", FileName);     return 0;}

Note: In LR, you can perform system internal commands and external commands for any Windows. You can look at the parameters in the environment variables and whether other commands are also supported.

If you have a Java environment, you can also execute Java commands, for example:

Action () {char command[1024]; sprintf (Command, "Java-javaagent:d:\testtools\Mercury\mercurydiagnostics\javaprobe\lib\probeagent.jar"     );    System (command); return 0;}

Translated from: http://www.ltesting.net

How to execute system commands in LoadRunner with the systems function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.