目标是自动执行3个文件:
如何自动执行这3个文件,以便在运行命令或执行文件时,所有3个文件都被执行?
这就是我的PowerShell的样子:
$Username = "";
$Password = "";
function Send-ToEmail([string]$email, [string]$attachmentpath) {
$message = New-Object Net.Mail.MailMessage;
$message.From = "c@c.com";
$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 "a@a.com" -attachmentpath "C:\file1";
Send-ToEmail -email "b@b.com" -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"
答案 0 :(得分: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
重复