![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Using @ as argument I'm writing a simple PS script to automate backup. The files are archived using RAR (no wordwrap, all on the same line): rar a -r -m1 -x@xxxxxx:\Tools\Scripts\backup_exclude.txt d:\Backup\epiajob $dayofweek.rar @c:\Tools\Scripts\backup_include.txt When running from cmd.exe, it works as intended. But running it inside the PS script, it gives: "Unrecognized token in source text.". I guess the parser don't like the @. How can I fix this? Thx in advance, Anders. |
My System Specs![]() |
| | #2 (permalink) | ||||||||||||
| Guest | Re: Using @ as argument Anders wrote:
where the problem is. -- Hal Rottenberg Blog: http://halr9000.com Webmaster, Psi (http://psi-im.org) Co-host, PowerScripting Podcast (http://powerscripting.net) | ||||||||||||
My System Specs![]() | |||||||||||||
| | #3 (permalink) | ||||||||||||
| Guest | Re: Using @ as argument Hal Rottenberg <hal@xxxxxx> wrote in news:Oe$$WH4WIHA.1132@xxxxxx:
At C:\Tools\epia_pscp_backup.ps1:18 char:85 + rar a -r -m1 -x@xxxxxx:\Tools\Scripts\backup_exclude.txt d:\Backup\epiajob $dayofweek.rar @ <<<< c:\Tools\Scripts\backup_include.txt | ||||||||||||
My System Specs![]() | |||||||||||||
| | #4 (permalink) | ||||||||||||||||||||||||
| Guest | Re: Using @ as argument You can't use the "@" sign unless you intend to pass an array, hashtable or a here-string. It's a special PowerShell character with special meaning, much like the "$" symbol. To compress a file with RAR try this: $winrar = "$env:ProgramFiles\WinRAR\WinRAR.exe" & $winrar a -m1 "d:\Backup\epiajob\$dayofweek.rar" "C:\Tools\Scripts\backup_exclude.txt" ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #5 (permalink) |
| Guest | Re: Using @ as argument If you ever need to pass an argument that starts with an @, you'll need to escape it using backtick. e.g. PS>t @c:\Tools\Scripts\backup_include.t Unrecognized token in source text. At line:1 char:3 + t <<<< @c:\Tools\Scripts\backup_include.t PS>t `@c:\Tools\Scripts\backup_include.t args = @c:\Tools\Scripts\backup_include.t -- Jeffrey P. Snover[MSFT] Partner Architect, Windows Server Microsoft Corporation This posting is provided "AS IS" with no warranties, and confers no rights. |
My System Specs![]() |
| | #6 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Using @ as argument Duh ![]() ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com
PS>>
PS>>
| ||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||
| | #7 (permalink) | ||||||||||||
| Guest | Re: Using @ as argument "Jeffrey Snover[MSFT]" <jsnover@xxxxxx> wrote in news:F0569015-872B-4D85-BCEC-8B385494074E@xxxxxx:
Thx, that did the trick :-) Regards, Anders | ||||||||||||
My System Specs![]() | |||||||||||||
| | #8 (permalink) | ||||||||||||
| Guest | Re: Using @ as argument Keep in mind that arguments are passed to external commands as an array of strings. If one of the arguments passed contains a character that has special meaning to Powershell then you will have to quote the string. The command works in CMD.EXE because CMD only recognizes the space character as a separator between arguments. If you needed to pass an argument that contained a space you would place double quotes around it. However, in Powershell there are several more more characters that you must be aware of, such as @, $, (, and ). There may be others. You may enclose the string argument in single or double quotes, but remember that a double quoted string will still need to use tic marks to escape the character. (e.g. `@, `$, `n, etc...) A single quoted string will have its content passes as literal. "Anders" <no@xxxxxx> wrote in message news:Xns9A2BB17CDA098nospamforme@xxxxxx
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #9 (permalink) | ||||||||||||
| Guest | Re: Using @ as argument "Jeffrey Snover[MSFT]" <jsnover@xxxxxx> wrote in message news:F0569015-872B-4D85-BCEC-8B385494074E@xxxxxx
[regex]::escape() escape that it would escape arguments? -- Keith | ||||||||||||
My System Specs![]() | |||||||||||||
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| P4P invalid argument encountered | nikro | Vista General | 3 | 07-27-2008 02:16 AM |
| run as administrator switch or argument | timb | Vista General | 2 | 04-05-2008 10:58 PM |
| Argument that starts with '-' and contains ':' gets separated. | Dan | PowerShell | 4 | 05-15-2007 01:50 PM |
| use a variable for -whatif argument | mario | PowerShell | 1 | 04-30-2007 04:11 PM |
| Command Line Argument Types | John Smith | PowerShell | 4 | 12-26-2006 11:13 AM |