From: Simon T. <si...@un...> - 2002-08-30 07:59:08
|
Hello Kevin, > Has anyone tried to control screen with expect? > > I would like to get a perl prog to start a screen > Then run an app and disconnect. > > Then at some time later (possibly weeks) connect to the screen and issue > commands to the prog running in the screen, with the possibility of > stoping (ctrl-c) and restarting the app in the same screen process > > screen -C "command" does not work as screen exits when the command exits I remember screen! Here is a quick script that seemed to work for me. (Well at least it is able to spawn "screen", get the help screen and then exit gracefully). If "screen" allows you to disconnect and leave programs running, then I suppose that you'll be able to do this via expect also. As an aside, Don Libes' "Exploring Expect" is a great reference for the (TCL) expect. It includes a fabulous script called "dislocate" (described at page 384) that does exactly what you want. Someone may have already implemented this via the perl Expect, in which case "screen" would not be required at all. Hope this helps. Regards, Simon Taylor #!/usr/bin/perl -w use strict; use Expect; my $screen="/usr/bin/screen"; my @args=("-S","bob"); my $app=Expect->spawn($screen,@args); $app->log_stdout(1); $app->log_user(1); unless ($app->expect(10,-re,"\$")){ print "did not get prompt\n"; exit; } print "got prompt\n"; $app->print("\ca?"); unless ($app->expect(10,"Press Space for next page; Return to end")) { print "did not see help screen\n"; exit; } print "got help prompt\n"; $app->print("\r"); # #Exit from help screen $app->hard_close(); print "done\n"; exit; -- Unisolve Pty Ltd - Melbourne, Australia +61 3 9568 2005 |