![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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) |
| | Re: Using @ as argument Anders wrote: Quote: > 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 @. 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) |
| | Re: Using @ as argument Hal Rottenberg <hal@xxxxxx> wrote in news:Oe$$WH4WIHA.1132@xxxxxx: Quote: > Can you paste the exact error? It will usually tell you the exact > character where the problem is. 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) |
| | 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 Quote: > 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 Quote: > > 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![]() |
| | #5 (permalink) |
| | 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) |
| | Re: Using @ as argument Duh ![]() ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com Quote: > If you ever need to pass an argument that starts with an @, you'll > need to escape it using backtick. e.g. > PS>> Quote: > Unrecognized token in source text. > At line:1 char:3 > + t <<<< @c:\Tools\Scripts\backup_include.t PS>> Quote: > args = @c:\Tools\Scripts\backup_include.t > |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Using @ as argument "Jeffrey Snover[MSFT]" <jsnover@xxxxxx> wrote in news:F0569015-872B-4D85-BCEC-8B385494074E@xxxxxx: Quote: > If you ever need to pass an argument that starts with an @, you'll > need to escape it using backtick. e.g. Thx, that did the trick :-) Regards, Anders |
My System Specs![]() |
| | #8 (permalink) |
| | 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 Quote: > 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![]() |
| | #9 (permalink) |
| | Re: Using @ as argument "Jeffrey Snover[MSFT]" <jsnover@xxxxxx> wrote in message news:F0569015-872B-4D85-BCEC-8B385494074E@xxxxxx Quote: > If you ever need to pass an argument that starts with an @, you'll need to > escape it using backtick. e.g. > [regex]::escape() escape that it would escape arguments? -- Keith |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| P4P invalid argument encountered | Vista General | |||
| Problem with an IF argument | .NET General | |||
| Internet argument! | Vista General | |||
| Argument that starts with '-' and contains ':' gets separated. | PowerShell | |||
| use a variable for -whatif argument | PowerShell | |||