![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||