0

I am trying to run a BCP command in windows machine powershell and unable to give input from a sql file.

Below command works fine in my MAC and I am looking for the same for Windows machine.

bcp "$(< /Users/mahendra.hegde/Desktop/input.sql)" queryout /Users/mahendra.hegde/dataout.json -c -T -S sample.env.compxyz.com

input.sql file scripts should be passed as input to bcp command when it runs.

I tried many ways in Windows but did not work, any help would be appreciated

Thanks

4

1 Answer 1

2

The equivalent of this bash command:

bcp "$(< /Users/mahendra.hegde/Desktop/input.sql)" queryout

is this PowerShell command:

bcp (Get-Content -Raw C:/Users/mahendra.hegde/Desktop/input.sql) queryout

Both commands pass the content of the specified file as a single, multiline string to the bcp utility; see the Get-Content cmdlet's documentation.

However, as of PowerShell 7.1, due to broken passing of arguments with embedded " characters - see this answer - more work is needed if the .sql file contains " characters; in the simplest case:

bcp ((Get-Content -Raw C:/Users/mahendra.hegde/Desktop/input.sql) -replace '"', '\"') queryout
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.