LinuxQuestions.org
Visit Jeremy's Blog.
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,079

Rep: Reputation: 368Reputation: 368Reputation: 368Reputation: 368
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: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,966
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
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: 27,019
Blog Entries: 54

Rep: Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


All times are GMT -5. The time now is 08:00 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration