简体   繁体   English

如何在我的ps脚本中执行cmd文件?

[英]how to Execute a cmd file in my ps script?

I have a cmd file which calls an msi and passes paramters. 我有一个调用msi并传递参数的cmd文件。 I am calling this deploy.cmd file from a powershell script. 我正在从Powershell脚本中调用这个deploy.cmd文件。 How can i achive this? 我怎样才能做到这一点?

I am may be missing something here. 我可能在这里错过了一些东西。

This is what my cmd looks like, 这就是我的cmd的样子

Msiexec /i ABCInstaller.msi ^
DB.SERVER=ABC\QA ^
APPLICATION.ENV.TYPE=Qa ^
SVCIDENTITY=SVC-QA@ABC.com ^
SVCPASSWORD=xxx ^
LOCAL.EMAILING="true" ^
EMAIL.GMAT="tarun.arora@abc.com" ^
EMAIL.GMATR="tarun.arora@abc.com" ^
EMAIL.SUCCESSFUL.VALIDATION.SUBJECT="[QA] Successful validation of ABC Message" ^
/lv "ABC_Installer_QA_Log.txt" 

This is what my powershell script looks like, 这就是我的Powershell脚本的样子,

# Assigning Build Number and Drop Location for the MSI in scope
$buildNumber = $TfsDeployerBuildData.BuildNumber
$dropLocation = $TfsDeployerBuildData.DropLocation

# Assign values
if($buildNumber -eq $null)
{
$buildNumber = $args[0]
$dropLocation = $args[1]
}

# Move old uninstall folder to Archive folder 
Move-Item "D:\deploy\ABC_Uninstalled\*" "D:\deploy\ABC_Archive" -force 

# Move old build folder to uninstalled folder 
Move-Item "D:\deploy\ABC_Installed\*" "D:\deploy\ABC_Uninstalled" -force 

# Logging 
Add-Content -Path "C:\Log\TfsDeployer_Log.txt" -Value $dropLocation 
Add-Content -Path "C:\Log\TfsDeployer_Log.txt" -Value $buildNumber 

# Copy the msi from drop location to local physical drive 
Copy-Item $dropLocation "D:\deploy\ABC_Installed" -recurse 
Add-Content -Path "C:\Log\TfsDeployer_Log.txt" -Value "Copied the Msi to D:\deploy\Installed"

# Start execution 
& "D:\deploy\ABC_Installed\$buildNumber\en-us\ETRM_QA.cmd" 

However when the ps is executed, It prints out what is inside the cmd file rather than executing it, so the output of the execution is 但是,当执行ps时,它将打印出cmd文件中的内容,而不是执行该文件,因此执行的输出为

Output: C:\WINDOWS\system32>Msiexec /i ABCInstaller.msi ^
DB.SERVER=ABC\QA ^
APPLICATION.ENV.TYPE=Qa ^
SVCIDENTITY=SVC-QA@ABC.com ^
SVCPASSWORD=xxx ^
LOCAL.EMAILING="true" ^
EMAIL.GMAT="tarun.arora@abc.com" ^
EMAIL.GMATR="tarun.arora@abc.com" ^
EMAIL.SUCCESSFUL.VALIDATION.SUBJECT="[QA] Successful validation of ABC Message" ^
/lv "ABC_Installer_QA_Log.txt" /passive T 

The cmd file is not executed :-( 该cmd文件未执行:-(

尝试:

Invoke-Expression "D:\deploy\ABC_Installed\$buildNumber\en-us\ETRM_QA.cmd"

MsiExec likely is executing, you are just not seeing it because it launches as a background process that immediately returns control to cmd. MsiExec可能正在执行,您只是没有看到它,因为它作为后台进程启动,立即将控制权返回给cmd。 For example, if I create a cmd script that looks like this: 例如,如果我创建一个如下所示的cmd脚本:

"C:\Program Files\Microsoft Office\Office11\WINWORD.EXE"

And invoke it like this: 并像这样调用它:

&launchWord.cmd

All I see on the powershell console is the contents of the cmd script, but word opens in another window. 我在powershell控制台上看到的只是cmd脚本的内容,但是word在另一个窗口中打开。 Are you sure msiexec isn't just launching and failing, rather than failing to launch? 您确定msiexec不仅会启动并失败,而且会失败吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM