Like Tree1Likes
  • 1 Post By anduril462

keypress simulation needed to complete process automation

This is a discussion on keypress simulation needed to complete process automation within the Linux Programming forums, part of the Platform Specific Boards category; Hey y'all. I wrote a daemon script to launch a second script that is responsible for monitoring/controlling a UI program. ...

  1. #1
    Registered User Annonymous's Avatar
    Join Date
    Apr 2011
    Location
    Jackson, New Jersey, United States
    Posts
    302

    keypress simulation needed to complete process automation

    Hey y'all. I wrote a daemon script to launch a second script that is responsible for monitoring/controlling a UI program. The problem is that if i run the daemon script on the command line like so: sh /path/to/daemon_script.sh, the monitor script causes the UI to not work correctly. Now if I run the contents of the daemon script manually on the command line like so: screen watch -n 60 /path/to/monitor_script.sh it works properly and runs every 60 seconds like it is supposed to. So, I am going to make a c program to see if it will work that way. I plan on using execl calls or something similar. Now here is where the problem lies; In order for the process to become daemonized, I need to manually hit control + A and control + D. That is what the screen command is for. Is there a way to simulate these key presses with C? I'll even settle for python, but would prefer C since that is what my entire program is based off of.

    Even a better way to do this would be cool. Suggestions, ideas?

    Thanks!
    Last edited by Annonymous; 05-16-2012 at 01:08 PM.

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,459
    Read through the man page for the screen utility. There are options that do exactly what you want. I'd tell you what they are, but that would take all the fun out of it .

  3. #3
    Registered User Annonymous's Avatar
    Join Date
    Apr 2011
    Location
    Jackson, New Jersey, United States
    Posts
    302
    This blows! I am trying to find the easiest approach to this and it seems any direction I decide to take will be complex!

    Someone else suggested to write a VTEmulator. Why write a few hundred line program for 150 lines of c code? If I were to write a VTE, I would definitely not do it in C. I would most likely do it in Python. I would say C++ but I dont like the feel of it and it is really ugly looking! No offense to any hard core C++ enthusiasts.

    I was also told I could use openpty, forkpty, etc. But there is very little documentation, if any, it assumes you know whats going on and does a horrible job explaining.

    The screen source; I have no idea what I'm looking for lol I guess that's why its so fun. Huh, Anduril?

    IDK... <sighs>
    Last edited by Annonymous; 05-16-2012 at 05:51 PM.

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,459
    Want a little cheese with your whine?

    Why do you think this is complex? What is difficult about starting your screen session/command in "detached" mode. There are options that the man page says are "useful for system startup scripts". Sounds like exactly what you want. So what exactly is the problem?
    Salem likes this.

  5. #5
    Registered User Annonymous's Avatar
    Join Date
    Apr 2011
    Location
    Jackson, New Jersey, United States
    Posts
    302
    I would love some!

    Idk, someone in another forum made it seem so. Like I was going to have to write 300 lines of code to make it all possible.

    automation with simulated keypresses in C programming

  6. #6
    Registered User Annonymous's Avatar
    Join Date
    Apr 2011
    Location
    Jackson, New Jersey, United States
    Posts
    302
    This did it. I guess I was whining over nothing. I feel so dumb now!!
    Code:
    CMD=$(screen watch -n 60 /home/annonymous/Documents/monitor.sh | xdotool key control+a | xdotool key control+D) && echo $CMD;

  7. #7
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,459
    Read the bloody screen man page! Seriously! You would have had this done 4 hours ago if you would have just read the documentation. You don't need that xdotool crap.

  8. #8
    Registered User Annonymous's Avatar
    Join Date
    Apr 2011
    Location
    Jackson, New Jersey, United States
    Posts
    302
    That actually just automates the daemon. Dint fix the issue. I still have the same problem; If i run a script that runs a script the UI does not print the open ports. The file does not even get written to. So if i run the monitord.sh file in /etc/init.d dir that runs the launcher/monitor script for the ui in my documents folder, it does not print to the file. The file is completely blank.

    I will be back when i have the solution. To the man pages.

    UPDATE: I used screens -dmS switch to replicate the above.

    Ok it works with
    Code:
    screen -dmS name watch -n 60 /home/annonymous/Documents/monitor.sh
    Thanks Anduril. Sorry for the aggrevation!
    Last edited by Annonymous; 05-16-2012 at 07:30 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OLE automation and C++
    By tkennedy in forum C++ Programming
    Replies: 3
    Last Post: 11-17-2006, 07:48 AM
  2. Help needed in creating a process
    By sac_garg in forum C Programming
    Replies: 3
    Last Post: 10-01-2006, 01:40 AM
  3. Complete compilable createProcess Example needed
    By Extolfreak in forum Windows Programming
    Replies: 6
    Last Post: 01-17-2006, 03:52 AM
  4. Automation Anywhere
    By danno.c in forum C# Programming
    Replies: 1
    Last Post: 08-07-2005, 10:10 AM
  5. Automation (or similar) without MFC
    By Robert602 in forum Windows Programming
    Replies: 0
    Last Post: 11-14-2002, 09:29 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21