腳本開發(fā)-執(zhí)行操作系統(tǒng)命令
by:授客
QQ:1033553122
思路:
用loadrunner
system()函數
函數原型:
int system( const char *string );
示例一:在指定目錄下創(chuàng)建指定文件
Action()
{
char filename[1024], command[1024];
char new_dir[] = "F:\\shouke";
// F盤下創(chuàng)建名為shouke的目錄,并把它作為當前目錄
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");
//
執(zhí)行“dir
/b
目錄命令”,并將結果寫入到一個新文件filename
sprintf(command, "dir /b F:\ > %s", filename);
system(command);
lr_output_message ("Created new file %s", filename);
return 0;
}
運行結果:



說明:
1.
dir
目錄:顯示目錄中的文件和子目錄列表
2.
dir
參數/b
目錄:不顯示修改日期等信息,只顯示文件名
示例二:執(zhí)行批處理
d盤根目錄下,創(chuàng)建test.bat文件,內容如下

腳本如下
Action()
{
system("d:\\test.bat");
return 0;
}
運行結果

|