I have following code to execute some commands on a virtue screen:screen -R << EOF    cd /home/users/devops_tester/apps/Selenium-Webdriver    export DISPLAY=:99    npm startEOFIt gives me an error:Must be connected to a terminal.How can I solve it?I found this related topics but I am not using ssh:How can I launch a screen session with a command over ssh on a remote server from my desktop?This is the screen app:https://packages.ubuntu.com/trusty/screen
Unable to run code in screen
ubuntu;bash;headless
First of all -R means you are attempting to resume an existing screen session that probably already runs something. In that case you can't just push your shell commands into it and hope they will be executed. What if the resumed screen session had for example an editor running? So, don't use -R when you want to specify a command to run.The other problem is that once you use input redirection through << __EOF__ the called program runs without a tty, i.e. without an interactive terminal. That can be easily demonstrated here:$ tty/dev/pts/0$ tty << __EOF____EOF__not a ttyFortunately for you screen has a support for running custom commands upon launch. It's as simple as screen command args (notice no -R in after screen).In your case you'll have to pass all your commands as arguments to /bin/sh because screen won't run multiple shell commands for you. Something like this should work:$ screen /bin/sh -cx cd /home/users/devops_tester/apps/Selenium-Webdriver; export DISPLAY=:99; npm startIt will spawn a new screen session and run your commands. The -x makes shell print the commands it runs for your reference. It's optional, you can remove it.You can also run the above in an immediately detached screen session and re-attach to it later:$ screen -d -m /bin/sh -cx cd /home/...; export ...; npm start# runs the commands in screen but returns immediatelyThat's useful if you want to run the commands during system startup for instance.And of course you can re-attach the above session to see what's going on there.$ screen -R    # re-attach to the above screen sessionLast but not least - instead of passing all your commands as arguments to /bin/sh it may be easier to create a little 3-liner shell script, make it executable and run that with a simple call:$ screen /path/to/the-scriptHope that helps :)