0

I am running a bash file through PuTTY. This is the contents of it:

#!/bin/bash
screen -X 'java -Xms2048m -Xmx2048m -jar mcpc.jar'
screen -x

When I run /backups/turnon.sh, it successfully connects to the screen however the java command is never run. Running the java command through PuTTY works fine. The bash file doesn't break at any point (as screen -x works fine), what's wrong?

DOK
  • 32,337
  • 7
  • 60
  • 92
Jon
  • 2,566
  • 6
  • 32
  • 52
  • 1
    You probably are trying to use both these questions (this one and [this one](http://stackoverflow.com/questions/22263204/screen-x-isnt-working-no-screen-found)) to debug the same issue, but please wait until one is answered before asking the other. – kojiro Mar 08 '14 at 01:12
  • @kojiro The other one was answered in the comments. I'm using them to solve two different issues with the same program. – Jon Mar 08 '14 at 01:26
  • How do you know 1. it successfully connects to the screen session and 2. the java command never runs? – kojiro Mar 08 '14 at 01:31
  • [Send commands to a GNU screen](http://stackoverflow.com/a/6065178/3278057) – user13500 Mar 08 '14 at 01:33
  • @Kojiro 1) Because I can use screen -x, and if it doesn't it sends `No screen session found.`. 2) Because when I enter the screen the output isn't there and the result of the java command doesn't exist. – Jon Mar 08 '14 at 01:37

1 Answers1

0

If you have not already, read the answer provided by Gilles here:

In short (to make some redundancy) the -X option expects a command. That is: a screen-command, not a shell/system command.

You could use the stuff-command. I.e.:

screen -X stuff 'java -Xms2048m -Xmx2048m -jar mcpc.jar

'

If you omit the command the target screen should respond with an error like:

-X: unknown command 'java -Xms2048m -Xmx2048m -jar mcpc.jar'

in the running screen window.


Notes:

  • At least here, I have to use double new-line at end of command. (Like example above).
  • As an alternative you can add the control character ^M, typically Ctrl+V Enter in Vim, bash etc. That inserts <CR>, byte 0x0d.
  • mcpc.jar must be in local path or provided by full/relative path.
Community
  • 1
  • 1
user13500
  • 3,817
  • 2
  • 26
  • 33