In Git Bash, how do I fix a "stdin is not a tty" error?
Asked Answered
H

2

6

I'm using Git Bash on Windows 10. I would like to import a SQL file to be run in my PostGres 12 local database. I tried the below

$ PGPASSWORD=$DB_PASSWORD psql -U${DB_USER} $DB_NAME < scripts/my-script.sql
stdin is not a tty

When I look in my database, the script hasn't been run, which leads me to believe the error message is telling me why, except I'm not sure what it means or how to fix it.

Harrier answered 20/7, 2022 at 14:19 Comment(1)
Did you try winpty? Did you search other related answers before you posted?Bystreet
S
5

Don't use redirection on Windows (in general, not just in "git-bash").

Pass the script file using the -f parameter:

PGPASSWORD=$DB_PASSWORD psql -U${DB_USER} -f scripts/my-script.sql $DB_NAME
Sink answered 20/7, 2022 at 14:30 Comment(3)
Can you elaborate? While in general "Don't use ... Windows" suits my taste, I can and do use redirections in Git Bash quite often. Is there a particular problem with psql? Or some other pitfall that I need to be watching for? I agree with your answer though -- simple and direct is almost always best.Bystreet
This command isn't working for me on Git Bash. I get a 'psql: warning: extra command-line argument "-f" ignored' warning and I'm then logged in to a normal psql session.Harrier
@Dave: sorry, $DB_NAME must be the last parameterSink
T
1

Replace psql with psql.exe

It has to do with the aliases that git-bash ships - psql is one of the handful of programs which has an alias. When I run cat /etc/profile.d/aliases.sh I see this line:

for name in node ipython php php5 psql python2.7 winget

For more information, check out these links:

Thumbstall answered 20/1 at 22:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.