命令提示符可以正确执行此操作,但Powershell不能执行吗? [英] Command Prompt executes this correctly but Powershell doesn't?

查看:328
本文介绍了命令提示符可以正确执行此操作,但Powershell不能执行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Powershell无法正确执行此命令的地方有些奇怪。它不能理解INSTALLFOLDER或TARGETDIR,而只是抛出Windows Installer帮助框。



而命令提示符对此进行了很好的处理???非常奇怪我相信PS版本是5.1.18362。



命令是

  msiexec.exe / i C: \Users\sadas\aasasdd\sda\asdasd\19526-Debug-x64.msi INSTALLFOLDER = C:\安装测试 / qn 

我的msi是Wix安装程序msi,具有属性INSTALLFOLDER

解决方案

这不是在PowerShell中运行此命令的方式。有几种方法可以在PowerShell中运行外部命令,并且它是有据可查的用例。跟随的链接


•使用PowerShell和外部命令及其参数或
开关。
运行外部命令时,始终需要特别注意。



•PowerShell:运行可执行文件



•解决PowerShell中外部命令行的问题



•在Powershell中运行外部命令的5条提示



•使用Windows PowerShell运行旧的命令行工具(和他们的
最奇怪的参数)



•在PowerShell中正确执行外部命令
https://mnaoumov.wordpress.com/2015/01/11/execution-of-external-commands-in-powershell-done-right

  https://mnaoumov.wordpress.com/2015/03/31/execution-of-external-commands-native-applications- in-powershell-done-right-part-2 

https://mnaoumov.wordpress.com/2015/04/05/execution-of-external-commands-native-applications-in-powershell -done-right-part-3

http://edgylogic.com/blog/powershell-and-external-commands-done-right

•详细信息

  https://trevorsullivan.net/2016/07/20 / powershell-quoting 




PowerShell包含一个字符列表,这些字符表示特定的内容,而不是cmd.exe实现的含义,如果需要,则必须正确终止它们。请参阅下面的


关于特殊字符



PowerShell-特殊字符和令牌


因此,要使您的命令在PowerShell控制台主机,ISE,VSCode中工作,请执行以下操作...

 #使用呼叫运算符
& 'msiexec.exe / i C:\Users\sadas\aasasdd\sda\asdasd\19526-Debug-x64.msi INSTALLFOLDER = C:\Installation Test / qn'



...这...

 #使用开始过程
$ ConsoelCommand ='msiexec.exe / i C:\Users\sadas \aasasdd\sda\asdasd\19526-Debug-x64.msi INSTALLFOLDER = C:\安装测试 / qn'
启动进程powershell -ArgumentList -NoExit,-命令& {$ ConsoleCommand}-等待


Having some weirdness where Powershell is not executing this command correctly. It can't understand the INSTALLFOLDER or TARGETDIR and just throws up the Windows Installer help box.

Whereas command prompt processes this just fine??? It's very weird. PS version is 5.1.18362 I believe.

the command is

msiexec.exe /i "C:\Users\sadas\aasasdd\sda\asdasd\19526-Debug-x64.msi" INSTALLFOLDER="C:\Installation Test" /qn

My msi is a Wix installer msi and has the property INSTALLFOLDER

解决方案

This is not how you run this command in PowerShell. There are several ways to run external command in PowerShell and it a well-documented use case. Links to follow

• Using PowerShell and external commands and their parameters or switches. Running external commands, always require special consideration.

• PowerShell: Running Executables

• Solve Problems with External Command Lines in PowerShell

• Top 5 tips for running external commands in Powershell

• Using Windows PowerShell to run old command-line tools (and their weirdest parameters)

• Execution of external commands in PowerShell done right https://mnaoumov.wordpress.com/2015/01/11/execution-of-external-commands-in-powershell-done-right

https://mnaoumov.wordpress.com/2015/03/31/execution-of-external-commands-native-applications-in-powershell-done-right-part-2

https://mnaoumov.wordpress.com/2015/04/05/execution-of-external-commands-native-applications-in-powershell-done-right-part-3

http://edgylogic.com/blog/powershell-and-external-commands-done-right

• Quoating specifics

https://trevorsullivan.net/2016/07/20/powershell-quoting

PowerShell has a list of characters that mean specific things, vs what cmd.exe implementation means, and if you need those, they must be properly terminated. See the below

About Special Characters

PowerShell - Special Characters And Tokens

So, to make your command work in the PowerShell consolehost, ISE, VSCode, do something like this...

# Using teh Call operator
& 'msiexec.exe /i "C:\Users\sadas\aasasdd\sda\asdasd\19526-Debug-x64.msi" INSTALLFOLDER="C:\Installation Test" /qn'

or

... this...

# Using Start-Process
$ConsoelCommand = 'msiexec.exe /i "C:\Users\sadas\aasasdd\sda\asdasd\19526-Debug-x64.msi" INSTALLFOLDER="C:\Installation Test" /qn'
Start-Process powershell -ArgumentList "-NoExit","-Command  &{ $ConsoleCommand }" -Wait

这篇关于命令提示符可以正确执行此操作,但Powershell不能执行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆