Find the answer to your Linux question:
Results 1 to 6 of 6
Hi! I'm currently writing a C++ application to manage some screen functions in Debian(server). However this issue have bothered me for 2 days now... What I want to do is ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2010
    Posts
    4

    Send enter command to screen?


    Hi!

    I'm currently writing a C++ application to manage some screen functions in Debian(server).

    However this issue have bothered me for 2 days now...

    What I want to do is to send a command to an attached screen which is running.
    Used the following command:
    Code:
    screen -S screenwindow
    So I send a command with the -X parameter, which works just fine...
    Code:
    screen -S screenwindow -X stuff yes
    The command I want to send is "yes" and it does appear in my screen window when I attach it.

    But the problem is that I need it to submit it... well I need to press "enter" and I've been looking everywhere on how to do that.

    Because right now it hangs on a line like this:
    Code:
    Something here, do you want bla bla: yes
    Obviously I could just press enter myself, but the problem is that it's running as a deamon and but it is supposed to do this all by itself .


    So are there any way I can submit it?

    Thanks

    - realchamp.

  2. #2
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    Try this:
    Code:
    screen -S screenwindow -X stuff $'\012'
    $'\012' means "newline character".

  3. #3
    Just Joined!
    Join Date
    Jun 2010
    Posts
    4
    Quote Originally Posted by Cabhan View Post
    Try this:
    Code:
    screen -S screenwindow -X stuff $'\012'
    $'\012' means "newline character".
    Hi! Thanks for the answer!

    Unfortunately it did not work.

    I wrote that line, after entering the command which would print "yes" and it didn't even register that I wrote the $ '\012'


    Thanks,
    - realchamp.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru coopstah13's Avatar
    Join Date
    Nov 2007
    Location
    NH, USA
    Posts
    3,149
    i would send a carriage return (\r), and maybe even followed by a new line (\r\n)

    I'm not sure what the corresponding value is with regards to what cabhan posted earlier

  6. #5
    Just Joined!
    Join Date
    Jun 2010
    Posts
    4
    Quote Originally Posted by coopstah13 View Post
    i would send a carriage return (\r), and maybe even followed by a new line (\r\n)

    I'm not sure what the corresponding value is with regards to what cabhan posted earlier
    Hey. Sorry for not replying.

    This solved the problem. I added the "\r" in the back.

    Thanks alot!

    - realchamp.

  7. #6
    Just Joined!
    Join Date
    Apr 2013
    Posts
    1

    Lightbulb Here is my solution:

    Quote Originally Posted by realchamp View Post
    Hey. Sorry for not replying.

    This solved the problem. I added the "\r" in the back.

    Thanks alot!

    - realchamp.
    C* users and bash addicts generally use a printf statement to achieve this goal:

    screen -S <screen name> -p 0 -X stuff "`printf "your command here\r"`";

    eg:
    # This opens a detatched screen in the background called test and passes pwd into it.
    Code:
    screen -dmaS test pwd
    # This sends the "exit" call to that now created screen:
    Code:
    screen -S test -p 0 -X stuff "`printf "exit\r"`";
    ! be aware that I found sending multiple commands to background screens needed a small buffer like sleep 0.2 or less to ensure no issues.


    firstpost!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •