Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
994 views
in Technique[技术] by (71.8m points)

windows installer - How to suppress quotes in PowerShell commands to executables

Is there a way to suppress the enclosing quotation marks around each command-line argument that PowerShell likes to generate and then pass to external executables for command-line arguments that have spaces in them?

Here's the situation:

One way to unpack many installers is a command of the form:

msiexec /a <packagename> /qn TARGETDIR="<path to folder with spaces>"

Trying to execute this from PowerShell has proven quite difficult. PowerShell likes to enclose parameters with spaces in double-quotes. The following lines:

msiexec /a somepackage.msi /qn 'TARGETDIR="c:some path"'

msiexec /a somepackage.msi /qn $('TARGETDIR="c:some path"')

$td = '"c:some path"'

msiexec /a somepackage.msi /qn TARGETDIR=$td

All result in the following command line (as reported by the Win32 GetCommandLine() API):

"msiexec" /a somepackage.msi /qn "TARGETDIR="c:some path""

This command line:

msiexec /a somepackage.msi TARGETDIR="c:some path" /qn

results in

"msiexec" /a fooinstaller.msi "TARGETDIR=c:some path" /qn

It seems that PowerShell likes to enclose the results of expressions meant to represent one argument in quotation marks when passing them to external executables. This works fine for most executables. However, MsiExec is very specific about the quoting rules it wants and won't accept any of the command lines PowerShell generates for paths have have spaces in them.

Is there a way to suppress this behavior?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Escape the inner quotes like this:

msiexec /a somepackage.msi TARGETDIR=`"c:some path`" /qn

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...