LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-17-2003, 02:22 AM   #1
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
execute command when program closes


how would i go about creating a shell script based 'launcher' menu that would respawn whenever the program launched quits? i would imagine such is possible considering how powerfull linux really is...
 
Old 11-17-2003, 02:25 PM   #2
MacKtheHacK
Member
 
Registered: Jul 2003
Location: Boston, MA, USA
Distribution: RedHat, SuSE, Gentoo, Slackware, Mandrake ...
Posts: 111

Rep: Reputation: 15
I'm not sure what you mean by "menu", but the basic way to respawn in a shell script is to write a function that loops running your program over and over. Start that function running in the background, and there you go. Here's a dumb example:

#! /bin/sh
respawn() {
while [ 1 ]
do "$@" </dev/null >/dev/null 2>&1
done
}
respawn sleep 5 &

I hope this is what you have in mind.
 
Old 11-17-2003, 04:05 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Re: execute command when program closes

Quote:
Originally posted by frieza
Micro$oft 1> /dev/null 2> /dev/null
Not lazy enough :} ... too much typing!

Micro$oft > /dev/null 2>&1

;)

Cheers,
Tink
 
Old 11-17-2003, 05:51 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
In the first place you should have told us which app or why it quits, there's usually lots of workarounds and alternatives, like if the app is a daemon, Google/see Freshmeat for "monit". Also see "man nohup".

Anyway, in your ~/.bashrc add this line:
restart() { "$@" && restart "$@"; }
start any app as usual, just prefix "restart".
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C program code to execute linux-command supermichou_fr Linux - Software 4 08-01-2012 08:25 AM
Execute a linux command using a java program tvalenzuela Programming 2 10-07-2005 11:59 AM
C function to execute a program and return the output of the program ryan.n Programming 4 08-14-2004 10:11 PM
Gtk-Warning but program still works... I close konsole, program closes Laptop2250 Linux - Software 2 11-14-2003 11:18 PM
ls command closes sftp connection SpecialK5106 Linux - Networking 4 11-03-2003 02:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration