| View previous topic :: View next topic |
| Author |
Message |
raider2k Op
Joined: 01 Jan 2008 Posts: 140
|
Posted: Mon Dec 07, 2009 6:51 am Post subject: [SOLVED] exec in bg |
|
|
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 
Last edited by raider2k on Mon Dec 07, 2009 4:45 pm; edited 1 time in total |
|
| Back to top |
|
 |
dj-zath Op
Joined: 15 Nov 2008 Posts: 134
|
Posted: Mon Dec 07, 2009 12:07 pm Post subject: |
|
|
Hi there
sure its possable!
I do it all the time
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-
 |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Mon Dec 07, 2009 2:59 pm Post subject: |
|
|
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 |
|
 |
raider2k Op
Joined: 01 Jan 2008 Posts: 140
|
Posted: Mon Dec 07, 2009 4:02 pm Post subject: |
|
|
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 |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Mon Dec 07, 2009 4:06 pm Post subject: |
|
|
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 |
|
 |
raider2k Op
Joined: 01 Jan 2008 Posts: 140
|
Posted: Mon Dec 07, 2009 4:24 pm Post subject: |
|
|
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 |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Mon Dec 07, 2009 4:26 pm Post subject: |
|
|
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 |
|
 |
raider2k Op
Joined: 01 Jan 2008 Posts: 140
|
Posted: Mon Dec 07, 2009 4:43 pm Post subject: |
|
|
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  |
|
| Back to top |
|
 |
|