Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Vista Tutorials Tags

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.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Using @ as argument

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 01-20-2008   #1 (permalink)
Anders
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 SpecsSystem Spec
Old 01-20-2008   #2 (permalink)
Hal Rottenberg
Guest


 

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 @.
Can you paste the exact error? It will usually tell you the exact character
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 SpecsSystem Spec
Old 01-20-2008   #3 (permalink)
Anders
Guest


 

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.
Unrecognized token in source text.
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 SpecsSystem Spec
Old 01-20-2008   #4 (permalink)
Shay Levi
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
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
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 SpecsSystem Spec
Old 01-20-2008   #5 (permalink)
Jeffrey Snover[MSFT]
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 SpecsSystem Spec
Old 01-20-2008   #6 (permalink)
Shay Levi
Guest


 

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>> t @c:\Tools\Scripts\backup_include.t
PS>>
Quote:

> 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
PS>>
Quote:

> args = @c:\Tools\Scripts\backup_include.t
>

My System SpecsSystem Spec
Old 01-20-2008   #7 (permalink)
Anders
Guest


 

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 SpecsSystem Spec
Old 01-20-2008   #8 (permalink)
Steven Hystad
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
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 SpecsSystem Spec
Old 01-21-2008   #9 (permalink)
Keith Hill [MVP]
Guest


 

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.
>
Hmm I wonder if PoSh could benefit from a utility method like
[regex]::escape() escape that it would escape arguments?

--
Keith

My System SpecsSystem Spec
Closed Thread

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


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51