自动化批处理文件和PowerShell脚本执行

问题描述 投票:-1回答:1

目标是自动执行3个文件:

  1. 运行selenium webdriver自动化测试套件的批处理文件。
  2. 生成测试报告的另一个批处理文件在步骤1中运行。
  3. 附加报告并发送电子邮件的PowerShell脚本。

如何自动执行这3个文件,以便在运行命令或执行文件时,所有3个文件都被执行?

这就是我的PowerShell的样子:

$Username = "";
$Password = "";
function Send-ToEmail([string]$email, [string]$attachmentpath) {
    $message = New-Object Net.Mail.MailMessage;
    $message.From = "[email protected]";
    $message.To.Add($email);
    $message.Subject = "abc";
    $message.Body = "abc";
    $attachment1 = New-Object Net.Mail.Attachment($attachmentpath);
    $message.Attachments.Add($attachment1);

    $smtp = New-Object Net.Mail.SmtpClient("build3", "25");
    $smtp.EnableSSL = $false;
    $smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
    $smtp.Send($message);

    Write-Host $smtp.EnableSSL;
    Write-Host "Mail Sent";
}

Send-ToEmail  -email "[email protected]" -attachmentpath "C:\file1";
Send-ToEmail  -email "[email protected]" -attachmentpath "C:\file1";

这是第一个批处理文件的样子:

FOR /F "TOKENS=2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET dd=%%A
FOR /F "TOKENS=2,3 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
FOR /F "TOKENS=2,3,4 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET yyyy=%%C
SET todaysdate=%yyyy%%mm%%dd%

start /d "nunitPATH" nunit3-console.exe "seleniumtestsuite dll PATH" --where:cat==SignUp --result="xmlreportPATH"

这是第二个批处理文件的样子:

start /d "exeFilePATH" ReportUnit.exe "folderPATH" 
powershell batch-file
1个回答
0
投票

只需编写一个运行的批处理脚本

call script1.bat
call script2.bat
D:\path\to\powershell.exe -File script3.ps1

如果你需要异步:

start script1.bat
start script2.bat
start "" "D:\path\to\powershell.exe" "-File" "script3.ps1"

请注意powershell.exe路径之前的双引号对。

请注意,这假设您的设备至少具有powershell v2

但是,这个问题与here重复

© www.soinside.com 2019 - 2024. All rights reserved.