ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Keith Hughitt" <keith.hugh...@gmail.com>
Subject Re: Trouble executing python script in Unix
Date Wed, 16 Jul 2008 14:51:08 GMT
Hi André,

Thanks for the suggestion. Python does find the script: Adding a print
statement
in the python script shows up during the build. Originally I thought that
the issue might be
due to the script not finding the input file. I now think, however, it may
be due to how python
interprets the angle brackets.

I once again added a "print sys.argv" which prints both the command executed
as well
as any arguments passed to it. Running the ant build results in:

[exec] Executing JSMin... arguments:
[exec] ['/var/www/hv/install/jsmin.py', '<proj-all.js>', 'proj-all-min.js']

Which I thought is what should be the output. However, running the same
script by itself,
the output (which actually goes to proj-all-min.js and not the command-line)
is:

Executing JSMin... arguments:
['./jsmin.py']


It looks like what is happening is that angle-brackets and the following
argument
specify streams to use for input and output, but for some reason when the
script
is run by ant, they are not interpreted this way. Perhaps the console is
still interpreting
them as escaped brackets (&lt; and &gt;), instead of actual angle brackets.
If that is
the case, it looks like I may be out of luck unless I rewrite the script to
initiate the filestreams
in another way.

The same script is available in other languages (Perl, etc), so I will try
another version that
doesn't make use of the angle-brackets. Then I should be able to tell if
this is actually the
root of the problem.

Thanks for taking the time to take a look at my problem, and for providing
feedback André.
And sorry for calling you Luis by accident last time.. Got my emails mixed
up :P

Take care,
Keith


On Wed, Jul 16, 2008 at 9:47 AM, André Pilz <andre.pilz@pcvisit.de> wrote:

> Seems like python doesn't find the script (because there is no error
> message).
>
> Possible solutions:
>
> - use absolute path for script location:
>        <arg value="${basedir}/install/tools/jsmin.py"/>
>
> - call script directly (like your working test.py):
>        <exec executable="${basedir}/install/tools/jsmin.py"
> resolveexecutable="true">
>            <arg value="&lt;/var/www/hv/lib/proj/build/proj-all.js&gt;"/>
>            <arg value="/var/www/hv/lib/proj//build/proj-all-min.js"/>
>        </exec>
>
> I also note the double slash in the last argument.
>
>
> Cheers,
> André
>
> Keith Hughitt schrieb:
>
>> Hi Luis,
>>
>> Thanks for the suggestion. I had tried using "ant -v" before, and also
>> redirecting the output, but was not aware of the '-d' parameter.
>> The script *should* result in a new file, "proj-all-min.js" being created.
>> The file is only created when I run the script manually, however,
>> and not when I call the script during an Ant build.
>>
>> Here is the relevant section of my build.xml as well as the complete
>> output
>> from execution:
>>
>> ========= BEGIN build.xml ===============
>> <project name="proj" default="build" basedir="../">
>> .
>> .
>> .
>>    <target name="build">
>>
>>        <!-- create build directory -->
>>        <mkdir dir="lib/proj/build"/>
>>
>>        <!-- test -->
>>        <exec dir="install" executable="test.py" resolveexecutable="true"/>
>>
>>        <!-- minify -->
>>        <exec dir="./" executable="python" resolveexecutable="true">
>>            <arg value="install/tools/jsmin.py"/>
>>            <arg value="&lt;/var/www/hv/lib/proj/build/proj-all.js&gt;"/>
>>            <arg value="/var/www/hv/lib/proj//build/proj-all-min.js"/>
>>        </exec>
>>
>>
>> ========= END build.xml ===========
>>
>> Note: Ant is run from /install, and thus "../" points to the project's
>> root
>> directory.
>>         The relevant python script is located in /install/tools, and
>> "test.py" is a dummy
>>         script located in /install that I used to test a simple case of
>> script execution.
>>
>> =========BEGIN OUTPUT===========
>>
>> $:/var/www/hv/install$ ant -d
>> Apache Ant version 1.7.0 compiled on August 29 2007
>> Buildfile: build.xml
>> Adding reference: ant.PropertyHelper
>> Detected Java version: 1.6 in: /usr/lib/jvm/java-6-sun-1.6.0.06/jre
>> Detected OS: Linux
>> Adding reference: ant.ComponentHelper
>> Setting ro project property: ant.file -> /var/www/hv/install/build.xml
>> Adding reference: ant.projectHelper
>> Adding reference: ant.parsing.context
>> Adding reference: ant.targets
>> parsing buildfile /var/www/hv/install/build.xml with URI =
>> file:/var/www/hv/install/build.xml
>> Setting ro project property: ant.project.name -> proj
>> Adding reference: proj
>> Setting ro project property: ant.file.proj ->
>> /var/www/hv/install/build.xml
>> Project base dir set to: /var/www/hv
>>  +Target:
>>  +Target: build
>> [antlib:org.apache.tools.ant] Could not load definitions from resource
>> org/apache/tools/ant/antlib.xml. It could not be found.
>> Attempting to create object of type
>> org.apache.tools.ant.helper.DefaultExecutor
>> Adding reference: ant.executor
>> Build sequence for target(s) `build' is [build]
>> Complete build sequence is [build, ]
>>
>> build:
>>     [exec] Current OS is Linux
>>     [exec] Executing '/var/www/hv/install/test.py'
>>     [exec] The ' characters around the executable and arguments are
>>     [exec] not part of the command.
>> Execute:Java13CommandLauncher: Executing '/var/www/hv/install/test.py'
>> The ' characters around the executable and arguments are
>> not part of the command.
>>     [exec] Hello World
>>     [exec] Current OS is Linux
>>     [exec] Executing 'python' with arguments:
>>     [exec] 'install/tools/jsmin.py'
>>     [exec] '</var/www/hv/lib/proj/build/proj-all.js>'
>>     [exec] '/var/www/hv/lib/proj//build/proj-all-min.js'
>>     [exec]
>>     [exec] The ' characters around the executable and arguments are
>>     [exec] not part of the command.
>> Execute:Java13CommandLauncher: Executing 'python' with arguments:
>> 'install/tools/jsmin.py'
>> '</var/www/hv/lib/proj/build/proj-all.js>'
>> '/var/www/hv/lib/proj//build/proj-all-min.js'
>>
>> The ' characters around the executable and arguments are
>> not part of the command.
>>
>> BUILD SUCCESSFUL
>> Total time: 0 seconds
>>
>> =========END OUTPUT===========
>>
>>
>> Any ideas?
>>
>>
>> Thanks,
>> Keith
>>
>>
>>
>>
>> On Wed, Jul 16, 2008 at 5:56 AM, André Pilz <andre.pilz@pcvisit.de>
>> wrote:
>>
>>  Hi,
>>>
>>> need more info to help you. Use "ant -d" to get the command line and the
>>> arguments how python is called. How exactly does it not work? Any error
>>> message?
>>>
>>> Cheers,
>>> André
>>>
>>> Keith Hughitt schrieb:
>>>
>>>  Hi all,
>>>
>>>> I've just recently started using Ant on Linux, and so far it has been
>>>> really
>>>> amazing. I've run into
>>>> one problem, however, that I haven't been able to get past.
>>>>
>>>> I would like to call an external script (a python script to minimize
>>>> some
>>>> JavaScript files),
>>>> but have not been able to get it to execute properly. I searched around
>>>> some, and found
>>>> an earlier thread (http://marc.info/?l=ant-user&m=115078380228196&w=2)
>>>> where someone with a similar problem was able to fix things setting
>>>> "resolveexecutable" to true.
>>>> This works for me when I try running a dummy script with no arguments,
>>>> e.g:
>>>>
>>>> ...
>>>> <exec dir="./" executable="test.py" resolveexecutable="true"/>
>>>> ...
>>>>
>>>> [exec] Hello World
>>>>
>>>>
>>>> When I try and do something requiring command-line arguments though I
>>>> can't
>>>> get it to work:
>>>>
>>>>       <exec dir="./" executable="python" resolveexecutable="true">
>>>>           <arg value="install/tools/jsmin.py"/>
>>>>           <arg value="&lt;${libs}/build/test.js&gt;"/>
>>>>           <arg value="${libs}/build/testl-min.js"/>
>>>>       </exec>
>>>>
>>>> I've tried executing both "python" (and passing the scripts name as an
>>>> argument), and the script itself.
>>>> Nothing seems to work. The command executes fine from the command-line,
>>>> and
>>>> what even more, when
>>>> I print the arguments passed to the python script using argv, and then
>>>> string them together and run them
>>>> it works fine, but still no luck when I try to get it working through
>>>> ant.
>>>>
>>>> Anyone have any suggestions as to what might be the problem?
>>>>
>>>> Any help would be greatly appreciated.
>>>>
>>>> Thanks,
>>>> Keith
>>>>
>>>>
>>>>  ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>> For additional commands, e-mail: user-help@ant.apache.org
>>>
>>>
>>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message