You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Laurence Mills-Gahl <el...@gmail.com> on 2011/01/24 03:27:52 UTC

Output of perl exec behaving oddly

I have an ant exec task that is behaving inconsistently.

I have a list of centerid's and a "foreach" loop that calls the
following target:

    <target name="compile_alert_report" description="compile  detail
report for alerts">
        <echo>patient detail for patients NOT on alert for center
${centerid}</echo>
        <exec dir="${center.bin}" executable="${perl}" failonerror="true">
            <arg line=" reportAlertDetail.pl -e ${report.enddate} -c
${centerid}  -A x -a x  -o ${report.xml}/${BUILDTIME}" />
        </exec>
    </target>

The report script (reportAlertDetail.pl) outputs some diagnostic
information, and is supposed to write the output to an xml file (in the
directory identified by the "-o" switch. (${report.xml}/${BUILDTIME} in
this instance)


The problem is that the first report or two is written as expected and
then the output (that should be written to a file) ends up in standard
output (and is also logged to the ant output under the [exec] task)
The scripts that produce the reports all work as expected (and have been
working as expected for a long time) when you call them from a shell or
a shell script (bash or csh).
I tried setting spawn="yes" on the exec task, but that that didn't do
much (except hide the stdout with all the file contents).

Does anybody have any idea what is going on or where I might look to
debug this?

/opt/ant/bin/ant -v
Apache Ant version 1.8.1 compiled on April 30 2010


Larry Mills-Gahl

Re: Output of perl exec behaving oddly

Posted by Laurence Mills-Gahl <el...@gmail.com>.
I wasn't looking at the ${BUILDTIME} property because I was assuming
that wouldn't change during the run, but it is (I noticed the output
directory created ended with 20110124103046 (the timestamp) and the
second invocation of compile_patients_on_alert was trying to write a
file to 20110124103052. So your initial comment on immutability of
properties was helpful because I was assuming  ${BUILDTIME} would not
change (and it did... yikes!)

Hmmmm... I'm going to have to look at the foreach task to see if it
creates an entirely new ant invocation with each iteration... that would
be the easy way to allow properties to change and it would explain why
the timestamp (that is only set in the top of the project) appears to
change when it shouldn't... hmmm. That would also explain the apparent
inconsistency in that if the execs were spawned quickly enough (when I
was trying spawn="yes" ) they might get into the same timestamped
directory, but then eventually, one wouldn't).

Hmmm... time to dig in to the foreach environment a bit.

Thanks for looking at this.

Larry

On 1/24/11 8:25 AM, Michael Ludwig wrote:
> Laurence Mills-Gahl schrieb am 24.01.2011 um 00:56 (-0500):
>> On 1/23/11 10:12 PM, Michael Ludwig wrote:
>>> Laurence Mills-Gahl schrieb am 23.01.2011 um 21:27 (-0500):
>>>> I have a list of centerid's and a "foreach" loop
>>> Red flag goes up …
>> What is the red flag?
> Ah, that was just a manner of speaking.
>
> I was on the wrong track, sorry. :-)
>
>> The foreach task (from Ant-Contrib) passes a parameter to the target
>> task. The ${centerid} is echoed on the target of the loop and it is
>> indeed changing as I would expect it to...
> Good - I had overlooked that possibility.
>
>> The script and commandline args are all correct and produce the
>> correct result when called from the shell.
>> The problem is that calling this from ant produces *inconsistent*
>> results. Some of the first report files are written but after two or
>> three iterations, the output that should be going to the file is
>> turning up in standard output.
>> The -d switch does provide lots of detail about what is going on at
>> each step and I don't see anything unexpected that would make the
>> output of an (apparently) separate process (the perl process) which is
>> outside the ant execution space, change from a perl file handle to
>> standard out.
> Another idea, but off-topic for Ant:
>
> Are you doing proper error checking on calls to open() in your Perl
> code?
>
>   open my $fh, '>', $fn or die "open $fn: $!"; # error checking
>
>> Thanks for your help, but I'm still on the hunt for why this is
>> happening.
> Good luck - someone else might have better ideas!
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Output of perl exec behaving oddly

Posted by Michael Ludwig <mi...@gmx.de>.
Laurence Mills-Gahl schrieb am 24.01.2011 um 00:56 (-0500):
> On 1/23/11 10:12 PM, Michael Ludwig wrote:
> > Laurence Mills-Gahl schrieb am 23.01.2011 um 21:27 (-0500):
> >>
> >> I have a list of centerid's and a "foreach" loop
> > Red flag goes up …
> 
> What is the red flag?

Ah, that was just a manner of speaking.

I was on the wrong track, sorry. :-)

> The foreach task (from Ant-Contrib) passes a parameter to the target
> task. The ${centerid} is echoed on the target of the loop and it is
> indeed changing as I would expect it to...

Good - I had overlooked that possibility.

> The script and commandline args are all correct and produce the
> correct result when called from the shell.
> The problem is that calling this from ant produces *inconsistent*
> results. Some of the first report files are written but after two or
> three iterations, the output that should be going to the file is
> turning up in standard output.

> The -d switch does provide lots of detail about what is going on at
> each step and I don't see anything unexpected that would make the
> output of an (apparently) separate process (the perl process) which is
> outside the ant execution space, change from a perl file handle to
> standard out.

Another idea, but off-topic for Ant:

Are you doing proper error checking on calls to open() in your Perl
code?

  open my $fh, '>', $fn or die "open $fn: $!"; # error checking

> Thanks for your help, but I'm still on the hunt for why this is
> happening.

Good luck - someone else might have better ideas!

-- 
Michael Ludwig

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Output of perl exec behaving oddly

Posted by Laurence Mills-Gahl <el...@gmail.com>.

On 1/23/11 10:12 PM, Michael Ludwig wrote:
> Laurence Mills-Gahl schrieb am 23.01.2011 um 21:27 (-0500):
>> I have an ant exec task that is behaving inconsistently.
>>
>> I have a list of centerid's and a "foreach" loop
> Red flag goes up …

What is the red flag?


>> that calls the following target:
>>
>>     <target name="compile_alert_report" description="compile  detail
>> report for alerts">
>>         <echo>patient detail for patients NOT on alert for center
>> ${centerid}</echo>
> Alert: Properties aren't variable. They're immutable. Their value does
> not change once set.


The foreach task (from Ant-Contrib) passes a parameter to the target
task. The ${centerid} is echoed on the target of the loop and it is
indeed changing as I would expect it to...
For example

<target name="generate_reports">
<foreach target="generate_reports_for_center" param="centerid"
list="${centerlist}" />
</target>

<target name="generate_reports_for_center" description="generate reports
for a particular centerid">
        <echo>generating reports for center ${centerid} through
${report.enddategraphs}</echo>
        <antcall target="compile_patient_detail_report">
            <param name="centerid" value="${centerid}" />
        </antcall>
    [...]
</target>

    <target name="compile_patient_detail_report" 
depends="render_graphs_for_center">

        <antcall target="compile_patients_on_alert">
            <param name="centerid" value="${centerid}" />
        </antcall>
      [...]
    </target>

    <target name="compile_patients_on_alert" description="compile
patient detail report for patients on alert">
        <echo>patient detail for alerting patients for center
${centerid}</echo>
        <echo message=" reportPatientDetail.pl -e ${report.enddate} -c
${centerid} -o ${report.xml}/${BUILDTIME} " />

        <exec dir="${center.bin}" executable="${perl}" failonerror="true">
            <arg line=" reportPatientDetail.pl -e ${report.enddate} -c
${centerid} -o ${report.xml}/${BUILDTIME} " />
        </exec>
    </target>

Where ${centerlist} is  "297,298,299,300,301" I get the echo message
with the correct ${centerid} as I expect. This is exactly how the
foreach task is supposed to behave and exactly the way it does behave in
a number of other areas of this project.

When it get's down to the "compile_patients_on_alert" target, the
arguments echoed to the console are correct (they are the same one's
that are used to call this script from the shell). This includes the
${centerid} (The rest of the properties in the command are the same for
the entire project run)

With the echo tasks showing that the command is forming as I expect, I
don't think this is an issue with properties.

>>         <exec dir="${center.bin}" executable="${perl}" failonerror="true">
>>             <arg line=" reportAlertDetail.pl -e ${report.enddate} -c
>> ${centerid}  -A x -a x  -o ${report.xml}/${BUILDTIME}" />
>>         </exec>
> More properties here. It's the same Perl script invocation each time
> around. That's probably not what you intend to do.

Actually, it's not the same perl script invocation. The ${centerid}
changes with each iteration of the foreach task.

Here is the echo output of an invocation to "generate_reports"

generate_reports:

va_common_targets.generate_reports:
     [echo] generating reports for center list
    [mkdir] Created dir: /home/VascAlert/reports/xml/20110124003823
    [mkdir] Created dir: /home/VascAlert/reports/pdf/20110124003823
     [copy] Copying 1 file to /home/VascAlert/reports/xml/20110124003823
     [copy] Copying 1 file to /home/VascAlert/reports/xml/20110124003823
     [copy] Copying 1 file to /home/VascAlert/reports/xml/20110124003823
     [copy] Copying 1 file to /home/VascAlert/reports/xml/20110124003823
     [copy] Copying 1 file to /home/VascAlert/reports/xml/20110124003823

generate_reports_for_center:
     [echo] generating reports for center 297 through 2011-01-24

compile_patient_detail_report:

compile_patients_on_alert:
     [echo] patient detail for alerting patients for center 297
     [echo]  reportPatientDetail.pl -e 2011-01-23 -c 297 -o
/home/VascAlert/reports/xml/20110124003824

compile_patients_not_on_alert:
     [echo] patient detail for patients NOT on alert for center 297

compile_access_report:
     [echo] access report for center 297

compile_alert_list_reports:
     [echo] VAPR alert list report for center 297
     [echo] AAPR alert list report for center 297

generate_reports_for_center:
     [echo] generating reports for center 298 through 2011-01-24

compile_patient_detail_report:

compile_patients_on_alert:
     [echo] patient detail for alerting patients for center 298
     [echo]  reportPatientDetail.pl -e 2011-01-23 -c 298 -o
/home/VascAlert/reports/xml/20110124003824

compile_patients_not_on_alert:
     [echo] patient detail for patients NOT on alert for center 298

compile_access_report:
     [echo] access report for center 298

compile_alert_list_reports:
     [echo] VAPR alert list report for center 298
     [echo] AAPR alert list report for center 298

generate_reports_for_center:
     [echo] generating reports for center 299 through 2011-01-24

compile_patient_detail_report:

compile_patients_on_alert:
     [echo] patient detail for alerting patients for center 299
     [echo]  reportPatientDetail.pl -e 2011-01-23 -c 299 -o
/home/VascAlert/reports/xml/20110124003824



The script and commandline args are all correct and produce the correct
result when called from the shell.
The problem is that calling this from ant produces *inconsistent*
results. Some of the first report files are written but after two or
three iterations, the output that should be going to the file is turning
up in standard output.



> There are a couple simple things you can do to find out what's going on.
>
> ant -h              # help
> ant -v              # verbose, some info
> ant -d              # debug, including properties getting set
> ant -diagnostics    # also useful to know what info is available here
>
> Take a look at the <listproperties> task, also occasionally useful to
> produce diagnostic output.
>

The -d switch does provide lots of detail about what is going on at each
step and I don't see anything unexpected that would make the output of
an (apparently) separate process (the perl process) which is outside the
ant execution space, change from a perl file handle to standard out.

Thanks for your help, but I'm still on the hunt for why this is happening.





Re: Output of perl exec behaving oddly

Posted by Michael Ludwig <mi...@gmx.de>.
Laurence Mills-Gahl schrieb am 23.01.2011 um 21:27 (-0500):
> I have an ant exec task that is behaving inconsistently.
> 
> I have a list of centerid's and a "foreach" loop

Red flag goes up …

> that calls the following target:
> 
>     <target name="compile_alert_report" description="compile  detail
> report for alerts">
>         <echo>patient detail for patients NOT on alert for center
> ${centerid}</echo>

Alert: Properties aren't variable. They're immutable. Their value does
not change once set.

>         <exec dir="${center.bin}" executable="${perl}" failonerror="true">
>             <arg line=" reportAlertDetail.pl -e ${report.enddate} -c
> ${centerid}  -A x -a x  -o ${report.xml}/${BUILDTIME}" />
>         </exec>

More properties here. It's the same Perl script invocation each time
around. That's probably not what you intend to do.

There are a couple simple things you can do to find out what's going on.

ant -h              # help
ant -v              # verbose, some info
ant -d              # debug, including properties getting set
ant -diagnostics    # also useful to know what info is available here

Take a look at the <listproperties> task, also occasionally useful to
produce diagnostic output.

-- 
Michael Ludwig

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org