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