Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3494382
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:59:58+00:00 2026-05-18T11:59:58+00:00

I am trying to send input to a interactive command running via screen. Here

  • 0

I am trying to send input to a interactive command running via screen. Here is my initial command

screen -L -c ./customrc -S psql -d -m /opt/PostgreSQL/9.0/bin/psql

The above command will run interactive psql in screen detach mode. The customrc is used to define a log file for the output (which I will read from another process by polling)

I am using following two commands to send input to psql running in screen

screen -S psql -X readreg p psqlcommands.sql
screen -S psql -X paste p

The problem is that the above commands do not work unless I reattach screen at least once. Once I have attached screen and detached, the above commands work as expected. I have to launch these commands via background java process hence the interactive shell (bash) is not available. My goal is to run psql in interactive mode and pass input to it and capture its output via a log file.

So far I have tried to run screen via xterm (or konsole or gnome-terminal) in attach mode, use readreg/paste and then detach, but I realise that xterm will not be available in my production environment. I’ve also tried sending output to /proc//fd/0 but I am unable to emulate ‘ENTER’ from keyboard (I have to attach and press in order for the output to be accepted by psql). I think pipes and fifo may help but I am unable to figure out how to proceed with them using screen and psql.

I appreciate any further hints or workarounds.

Thank you,

Usman.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T11:59:58+00:00Added an answer on May 18, 2026 at 11:59 am

    FINAL ANSWER: It is a bug/feature in ‘GNU screen’ that it needs a DISPLAY atleast once for ‘paste’ command to work. Following are possible workarounds this problem:

    Finally figured out how to utilise psql with pipes and screen. Here is the solution:

    mkfifo psql.pipe
    screen -L -c ./customrc -S psql -d -m bash -i -c "while (true); do cat psql.pipe; done | /opt/PostgreSQL/9.0/bin/psql -a"
    

    After that, I can cat my commands to the pipe:

    cat ./mycommands.sql > psql.pipe
    

    To quit from screen and terminating psql, I used

    screen -S psql -X quit
    

    EDIT: (finally) figured out the solution for my problem without using screen command. Meet ‘empty‘ utility.

    empty -f -i psql.in -o psql.o -p psql.pid <psqlpath>
    

    This allows psql to run in full interactive mode as opposed to the original solution that I used (in which psql does not run in interactive mode).

    Thanks.

    Usman

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.