You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Melissa Hao <me...@oracle.com> on 2003/05/06 23:55:37 UTC

Re: antRunAsync and getting a background process to run indefinitely

Hi Bill,

In emacs, I am using the compile command to run ant, which I believe starts up an inferior shell.  I can't figure this problem out, so I'll try the emacs newsgroup.  I'm afraid zsh isn't an option... I have to use emacs because my development environment is centered around emacs.

--
thanks
Melissa



Bill Burton wrote:

> Hello Melissa,
>
> Melissa Hao wrote:
> > Well it turns out the problem has been emacs.  Sorry to make you go through all that trouble!
> >
> > I am running ant from inside emacs.  After the compilation process terminates, the java process terminates.  When I run ant outside of emacs, it works (ie the java process continues after the ant process terminates).  So my question is really an emacs question.  Does anyone happen to know how to get around this?  (I've spent some time looking at this and I can't figure it out... I need something like emacsRunAsync  :)
>
> Okay.  Are you using shell-mode or the command to run Make, or something
> else?  It's likely emacs is sending a SIGHUP or SIGTERM to the child
> processes with the assumption nothing should be left running.  Maybe
> there's a setting that can be changed in that emacs mode to change that
> behavior.  If you can't find anything to change the behavior, you should
> ask on an emacs list or newsgroup.
>
> If you can't find a work around for emacs, I'd suggest using a more
> capable shell such as Z-Shell (zsh) from an xterm window, etc.  The old
> version 3.x included with Solaris 8 is still more capable than tcsh or
> bash and you can use the csh bang history commands as well.
>
> -Bill
>
> > --
> > thanks
> > Melissa
> >
> >
> >
> >
> > Bill Burton wrote:
> >
> >
> >>Hello Melissa,
> >>
> >>Melissa Hao wrote:
> >>
> >>>Hi Bill,
> >>>
> >>>I am using Solaris 5.8 and csh.  The bgtest (ant exec_output) appears to work.
> >>>
> >>>I'm not sure if my setup is correct... let me describe my setup to you and you can tell me if I'm invoking oc4j.sh correctly.
> >>
> >>Your setup looks correct.  The fact that you can successfully run the
> >>bgtest script but not your oc4j.sh script is puzzling.  I'm wondering if
> >>  csh isn't sending some signal to all child processes when Ant exits
> >>which causes the java process to exit.
> >>
> >>As another person pointed out, maybe you should try modifying the script
> >>and adding a "nohup" in front of the java command.
> >>
> >>I tried to reproduce the problem but could not.  Ran Ant from csh with a
> >>java class that did a Thread.sleep(5000).  It always finished
> >>successfully after Ant had already finished.  When Ant finished running,
> >>I could run "ps" a few times and see the java process was still active.
> >>
> >>-Bill
> >>
> >>
> >>>Here's the relevant part of my build.xml:
> >>>
> >>>    <property name="antRunAsync" value="/home/mhao/packages/antRunAsync/bin/antRunAsync"/>
> >>>    <exec executable="${antRunAsync}" dir="${j2ee.home}" vmlauncher="false" failonerror="true">
> >>>      <env key="ANTRUN_OUTPUT" value="oc4j2.log"/>
> >>>      <env key="ANTRUN_NOHUP" value="true" />
> >>>      <arg line="oc4j.sh start"/>
> >>>    </exec>
> >>>
> >>>oc4j.sh is a shell script that does many things.  In the middle of the script, it starts up a java process:
> >>>
> >>>    ${JAVA_HOME}/bin/java -server -Xmx256m -jar ${J2EE_HOME}/oc4j.jar > ${J2EE_HOME}/oc4j.log 2>&1 &
> >>>
> >>>I would like the following two conditions to be met:
> >>>- After processing the antRunAsync exec task, ant does not wait for the java process to complete before going to the next task.  (This condition is currently being met.)
> >>>- The java process continues after the ant process finishes.  (This condition is not currently being met.)
> >>>
> >>>Am I setting up things correctly?
> >>>
> >>>thanks
> >>>Melissa
> >>>
> >>>
> >>>
> >>>Bill Burton wrote:
> >>>
> >>>
> >>>
> >>>>Hello,
> >>>>
> >>>>Melissa Hao wrote:
> >>>>
> >>>>
> >>>>>Hi,
> >>>>>
> >>>>>I'm having trouble getting the antRunAsync workaround to work exactly the way I want.
> >>>>>
> >>>>>I use antRunAsync to run a shell script called oc4j.sh.  The shell script is started asynchronously, which is great.  The shell script spawns a java process in the background (eg, "java foo.bar &").  I would like this java process to continue running after the ant process completes.  Currently, the java process stops when the ant process stops.  Is there any way to get the java process to run indefinitely?
> >>>>
> >>>>I'm a little puzzled as to why this would be happening.  First, your
> >>>>oc4j.sh script would already be run in the background by the antRunAsync
> >>>>script.  If the only thing (or the last thing) your script does is to
> >>>>start "java foo.bar" in the background, the "&" isn't necessary.  Only
> >>>>if you want to start another process without waiting for that to
> >>>>complete would you need to put your java command in the background.
> >>>>
> >>>>Can you run the bgtest script and build file included in the archive to
> >>>>see if you have the same problem?
> >>>>
> >>>>Although this shouldn't be necessary, you could try redirecting all the
> >>>>standard file descriptors, i.e.
> >>>>    java foo.bar </dev/null >foo.bar.out 2>&1 &
> >>>>This is what antRunAsync does if you specify
> >>>>    <env key="ANTRUN_OUTPUT" value="some-output-file" />
> >>>>to <exec> so it shouldn't be necessary.
> >>>>
> >>>>What OS are you running on and what shell are you using?  Before posting
> >>>>antRunAsync, the only UNIX OS I'd tested on was Solaris 2.8.  But in
> >>>>theory, it should work the same way on all other UNIX OS's.
> >>>>
> >>>>-Bill
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org


Re: antRunAsync and getting a background process to run indefinitely

Posted by "Jeffery B. Rancier" <je...@softechnics.com>.
Melissa Hao <me...@oracle.com> writes:

>> > I am running ant from inside emacs.  After the compilation
>> > process terminates, the java process terminates.  When I run ant
>> > outside of emacs, it works (ie the java process continues after
>> > the ant process terminates).  So my question is really an emacs
>> > question.  Does anyone happen to know how to get around this?
>> > (I've spent some time looking at this and I can't figure it
>> > out... I need something like emacsRunAsync  :)

I'm assuming you are trying to run a Java application, and it's
terminating?  I do this from within Emacs, with jde-ant-build command,
and a sample run task looks like:

,----
|     <target name="run" depends="compile"
|             description="Executes the project main class">
| 
|         <java classname="${project.execute.classname}"
|             dir="${build.classes}"
|             fork="yes">
|             <jvmarg line="-Xbootclasspath/p:lib\jdk118_classes.zip"/>
|             <classpath refid="classpath"/>
|             <arg line="-h anArg -p 7777 -d"/>
|         </java>
| 
|     </target>
`----

Is that what you're looking for?

-- 
Thanks,
Jeff
,----
| Jeffery B. Rancier
| 
| Softechnics
| a METTLER TOLEDO company
`----