1

I'm running a powershell script on a windows system. The script includes psql commands to run SQL on a postgres database.

Most stuff gets correctly recorded in the powershell log file, EXCEPT for psql errors.

My powershell script uses this to start logging...

$script:logFile = "C:\temp\log\mylog.dat" 

# Start logging to file......
Start-Transcript -Append $script:logFile

And then uses psql commands to connect to the database and do stuff...

.\psql -U myuser -d mydatabase -c "do database stuff here...."

This works - in the sense that it executes correctly, but any database errors that appear on the console don't get logged to "C:\temp\log\mylog.dat".

I've tried explicitly logging to the file using this....

.\psql -U myuser -d mydatabase -c "do database stuff here...." -L "C:\temp\log\mylog.dat"

This doesn't work.

And I've tried re-directing stderr to stdout....

.\psql -U myuser -d mydatabase -c "do database stuff here...." 2>&1

This doesn't work either.

How do I direct everything from the psql command to the same log file as all the other (non-database) commands in the powershell script?

0

Your Answer

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

Browse other questions tagged or ask your own question.