crosby.tim.TakeThisOut@gmail.com wrote:
> I'm trying to accomplish something that I thought would be very simple.
> I guess I'm just missing something but here goes.
>
> I want to simply call an executable from within my Monad script and
> send that executable a parameter in the form of a variable set earlier
> in the script. More specifically, I'm trying to call the command line
> version of WINRAR and give it a date so it will zip anything older than
> that date.
>
> If I type either of these commands into powershell, it works as
> expected:
>
> .. 'C:\Program Files\WinRAR\rar.exe' a -tb20060504 -m5 ziplogs.zip
> or
> & 'C:\Program Files\WinRAR\rar.exe' a -tb20060504 -m5 ziplogs.zip
>
> What I want to do is use a $variable to replace the 20060504. I first
> verify that my variable resolves to 20060504 So I try:
>
> & 'C:\Program Files\WinRAR\rar.exe' a -tb$variable -m5 ziplogs.zip
> or
> .. 'C:\Program Files\WinRAR\rar.exe' a -tb$variable -m5 ziplogs.zip
>
> I don't get any errors, but with both of those commands winrar zips
> everything and ignores the date variable. What is the proper syntax to
> pass a variable as a parameter to an external command?
>
you need to use quotes around the parameter as winrar wants them
connected (no space) and powershell thinks the $ is part of the parameter.
.. 'C:\Program Files\WinRAR\rar.exe' a "-tb$variable" -m5 ziplogs.zip
see this resolving :
MowPS>echo 'C:\Program Files\WinRAR\rar.exe' a -tb$variable -m5 ziplogs.zip
C:\Program Files\WinRAR\rar.exe
a
-tb$variable
-m5
ziplogs.zip
MowPS>echo 'C:\Program Files\WinRAR\rar.exe' a "-tb$variable" -m5
ziplogs.zip
C:\Program Files\WinRAR\rar.exe
a
-tb20060504
-m5
ziplogs.zip
greetings /\/\o\/\/
>> Stay informed about: Passing a Monad (powershell) variable as command parameter