egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[SOLVED] exec in bg

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
raider2k
Op


Joined: 01 Jan 2008
Posts: 140

PostPosted: Mon Dec 07, 2009 6:51 am    Post subject: [SOLVED] exec in bg Reply with quote

hey guys (and girls ^^)

looking for a solution to kind of call a shell script (.sh) which takes about 3 minutes to be finished into background without getting my eggdrop stuck and not responding at all.

fact is: its not possible to do it with exec since exec waits for a reply
possible solution: using something like set x [open "| myscript.sh"]?

do I also need a set x2 [read $x] or what else is needed to make it work, do I miss something in general anyway?

thx for all your help Smile


Last edited by raider2k on Mon Dec 07, 2009 4:45 pm; edited 1 time in total
Back to top
View user's profile Send private message
dj-zath
Op


Joined: 15 Nov 2008
Posts: 134

PostPosted: Mon Dec 07, 2009 12:07 pm    Post subject: Reply with quote

Hi there

sure its possable!

I do it all the time Smile

heres an example:

Code:

catch {exec ./Pisg -co Pisg.cfg >/dev/null &};


heres one where I insert an some varables

Code:

exec ./fetch -q -A -m -T 1 -o /dev/null "http://$RacIP:$RacPort/x/playing.cgi?c=$command" >& /dev/null};


let me know if this helps.

-DjZ-
Smile Smile
Back to top
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Mon Dec 07, 2009 2:59 pm    Post subject: Reply with quote

Whether to use exec or open pretty much comes down to whether you need to maintain contact with the shell script (send text to it, read it's output, know if it's still running or not), or simply a "fire and forget" script...

If you don't care for what the script is doing or when it's completed, exec should do the trick. See the manpage for a list of possible pipe controls (&, |, etc).

If, however, you need to keep track of the script while it's running, you'll need to use open. As for reading the generated output, you'd probably use fileevents for this. I'd also recommend setting the file channel into non-blocking mode. There's a few good examples how to get all this working on the forum, but feel free to ask if you need further assistance with it.
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
raider2k
Op


Joined: 01 Jan 2008
Posts: 140

PostPosted: Mon Dec 07, 2009 4:02 pm    Post subject: Reply with quote

uhm, I think im fine with a so called "fire and forget" solution, although Im not sure which solution you are suggesting now oO

so exec $shellscript >/dev/null is meant to do the trick, launch the script into bg and NOT block the remaining code?
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Mon Dec 07, 2009 4:06 pm    Post subject: Reply with quote

Not quite, that would launch the script and redirect the stdout of the script to /dev/null. It would, however, still block while the script is running. The key part is this (quoted from the manpage):
Quote:
If the last arg is ''&'' then the pipeline will be executed in background. In this case the exec command will return a list whose elements are the process identifiers for all of the subprocesses in the pipeline. The standard output from the last command in the pipeline will go to the application's standard output if it hasn't been redirected, and error output from all of the commands in the pipeline will go to the application's standard error file unless redirected.

So, what you need to do is suffix the commandline with a &
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
raider2k
Op


Joined: 01 Jan 2008
Posts: 140

PostPosted: Mon Dec 07, 2009 4:24 pm    Post subject: Reply with quote

oh, oh?
exec $myshellscript &
is going to do the trick and ill never have a non-responding bot again when calling something that takes a hell of a time via exec?
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Mon Dec 07, 2009 4:26 pm    Post subject: Reply with quote

Yup,
Since your eggie runs in the background, you'll probably want to redirect stdout and stderr to /dev/null to avoid garbage being spewed out to the terminal where you started your eggie, but & is enough to make the exec-call "non-blocking".
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
raider2k
Op


Joined: 01 Jan 2008
Posts: 140

PostPosted: Mon Dec 07, 2009 4:43 pm    Post subject: Reply with quote

well I dont think Im going to see the garbage my eggy spews out since Im not logged on to the same terminal window all the time :>

but thanks so far, Im going to try that next time Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber