Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Escape comma in dos command from PS script

Reply
 
Old 06-27-2007   #1 (permalink)
Brian Vallelunga


 
 

Escape comma in dos command from PS script

I'm trying to execute a sql BCP call from within a Powershell script
and am running into a problem.

The line of code looks like:

bcp "SELECT * FROM Clinton08..Customer" queryout "D:\SQL Data\Exports
\Data.csv" -c -t, -k -T

The problem lies in the -t, which sets the field terminator as a
comma. Powershell treats this as if it was an array separator and not
a comma. Any thoughts on how to get around this? I tried `, but that
didn't work. Perhaps I need to use Invoke-Expression? That seemed to
give the same problem though.

Thanks,
Brian


My System SpecsSystem Spec
Old 06-27-2007   #2 (permalink)
Brian Vallelunga


 
 

Re: Escape comma in dos command from PS script

After two hours of working on this and three minutes after posting, I
found a solution. For everyone's enjoyment, the following works:

bcp 'SELECT * FROM Clinton08..Customer' queryout 'D:\SQL Data\Exports
\Data.csv' -c "-t," -k -T


On Jun 27, 12:22 pm, Brian Vallelunga <brian.vallelu...@gmail.com>
wrote:
> I'm trying to execute a sql BCP call from within a Powershell script
> and am running into a problem.
>
> The line of code looks like:
>
> bcp "SELECT * FROM Clinton08..Customer" queryout "D:\SQL Data\Exports
> \Data.csv" -c -t, -k -T
>
> The problem lies in the -t, which sets the field terminator as a
> comma. Powershell treats this as if it was an array separator and not
> a comma. Any thoughts on how to get around this? I tried `, but that
> didn't work. Perhaps I need to use Invoke-Expression? That seemed to
> give the same problem though.
>
> Thanks,
> Brian



My System SpecsSystem Spec
Old 06-28-2007   #3 (permalink)
Keith Hill [MVP]


 
 

Re: Escape comma in dos command from PS script

"Brian Vallelunga" <brian.vallelunga@gmail.com> wrote in message
news:1182961989.062942.144260@q69g2000hsb.googlegroups.com...
> After two hours of working on this and three minutes after posting, I
> found a solution. For everyone's enjoyment, the following works:
>
> bcp 'SELECT * FROM Clinton08..Customer' queryout 'D:\SQL Data\Exports
> \Data.csv' -c "-t," -k -T
>


PowerShell Community Extensions has simple little utility exe that lets you
know how your parameters have been parsed by PowerShell and sent to an exe
e.g.:

13> echoargs "SELECT * FROM Clinton08..Customer" queryout "D:\SQL
Data\Exports\Data.csv" -c -t, -k -T
Arg 0 is <SELECT * FROM Clinton08..Customer>
Arg 1 is <queryout>
Arg 2 is <D:\SQL Data\Exports\Data.csv>
Arg 3 is <-c>
Arg 4 is <-t>
Arg 5 is <-k>
Arg 6 is <-T>

Of course you still would have had to figure out the bit about quoting
the -t, arg. I find handy because I don't have to guess how the exe
received its args. This gets trickier if args have embedded ';' which is a
statement terminator in PowerShell.

--
Keith Hill
http://www.codeplex.com/powershellcx

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Running a command from inside a script, command line is corrupted PowerShell
My command works in the PS prompt but not in a script (.ps1) / reg PowerShell
Script DOS Command? VB Script
problem in script with dsmod command PowerShell
Script from command-line PowerShell


Vista Forums 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 Ltd

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