sshgnu-screenheredoccentos8herestring

Running a command that includes an STDIN redirect with screen


Using the Gradle SSH plugin I deploy a .jar file to another machine.

I then would like to run that jar in a detached screen session. This wouldn't be a problem if the application did not require input on STDIN, running screen -dmS screen-name java -jar my.jar.

I tried to provide the input (beside others approaches) in the following way using a here-string, yet I did not get any of them to work:

screen -dmS screen-name java -jar my.jar <<< "firstInputLine
SecondInputLine
"

Can anyone point me in the right direction? Thanks!


Solution

  • I currently solved this by first creating the detached screen session an then, with a second screen call, forwarding the input using screen's stuff command, not using a here-string anymore:

    screen -dmS screen-name java -jar my.jar && 
    screen -S screen-name -p 0 -X stuff "firstInputLine^MsecondInputLine^M"
    

    (^M is interpreted as ENTER)