This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

run Perl script from Ant file

 
Sheila Durrant
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm new to Ant. I'm trying to run a Perl script (using exec) from Ant. I get alot of errors that you can see below. I'm running Ant 1.6.1 and active state Perl v5.8.0 built for MSWin32-x86-multi-thread, working on Windows.

The first part of my build script is:

<project name="HelloWorld" default="compile">
<description>
very simple test
</description>

<target name="init">
<!-- Create the time stamp -->
<tstamp/>
</target>

<property name="ViewName" value="sheila_temp"/>


<target name="create_view" depends="init">
<!-- Building MAPI -->
<exec dir="c:\scripts"
executable="perl c.pl" os="Windows 2000" output="output2.txt">
</exec>
</target>

I've also tried "executable="c.pl"", but that didn't work either. I can run the Perl script by itself from a DOS prompt. I'm trying to run a Perl script called c.pl from c:\scripts.

The errors I get are below:
C:\temp2>ant -v
Apache Ant version 1.6.1 compiled on February 12 2004
Buildfile: build.xml
Detected Java version: 1.4 in: c:\j2sdk1.4.2_04\jre
Detected OS: Windows 2000
parsing buildfile C:\temp2\build.xml with URI = file:///C:/temp2/build.xml
Project base dir set to: C:\temp2
Build sequence for target `compile' is [init, create_view, compile]
Complete build sequence is [init, create_view, compile, ]

init:

create_view:
[exec] Current OS is Windows 2000
[exec] Output redirected to C:\temp2\output2.txt
[exec] Executing 'perl c.pl' with

BUILD FAILED
C:\temp2\build.xml:18: Execute failed: java.io.IOException: CreateProcess: "perl
c.pl" error=2
at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:569)
at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:415)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:269)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:301)
at org.apache.tools.ant.Target.performTasks(Target.java:328)
at org.apache.tools.ant.Project.executeTarget(Project.java:1215)
at org.apache.tools.ant.Project.executeTargets(Project.java:1063)
at org.apache.tools.ant.Main.runBuild(Main.java:632)
at org.apache.tools.ant.Main.startAnt(Main.java:183)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:197)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:56)
Caused by: java.io.IOException: CreateProcess: "perl c.pl" error=2
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Win32Process.java:66)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.tools.ant.taskdefs.Execute$Java13CommandLauncher.exec(Exec
ute.java:808)
at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:445)
at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:459)
at org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:525)
at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:566)
... 11 more
--- Nested Exception ---
java.io.IOException: CreateProcess: "perl c.pl" error=2
at java.lang.Win32Process.create(Native Method)
at java.lang.Win32Process.<init>(Win32Process.java:66)
at java.lang.Runtime.execInternal(Native Method)
at java.lang.Runtime.exec(Runtime.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.tools.ant.taskdefs.Execute$Java13CommandLauncher.exec(Exec
ute.java:808)
at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:445)
at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:459)
at org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:525)
at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:566)
at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:415)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:269)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:301)
at org.apache.tools.ant.Target.performTasks(Target.java:328)
at org.apache.tools.ant.Project.executeTarget(Project.java:1215)
at org.apache.tools.ant.Project.executeTargets(Project.java:1063)
at org.apache.tools.ant.Main.runBuild(Main.java:632)
at org.apache.tools.ant.Main.startAnt(Main.java:183)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:197)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:56)

Total time: 1 second

What am I doing wrong?

Thanks,

Sheila

 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error code 2 apparently means that the perl program is not on your path. So, either set your PATH settings correctly, or run it from the perl/bin directory.
 
Sheila Durrant
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for your response. However, I don't think that is the problem because:
-The perl script can be run from a normal DOS prompt *not* , in the Perl directory
-Also I can type perl -v (to get the version) in any directory and that works.

Any other thoughts?

Thanks,

Sheila
 
Sheila Durrant
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

It looks like I solved my own question, by using a clue from a posting at:
http://www.jguru.com/forums/view.jsp?EID=1162658

It seems to work if I use the exec command to open a "cmd" window like this:

<target name="create_view" depends="init">
<!-- Creating view -->
<exec dir="." executable="cmd" os="Windows 2000" output="output2.txt">
<arg line="/c start c:\scripts\c.pl"/>
</exec>
</target>

Thanks,

Sheila
 
kri shan
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sheila,
<target name="create_view" depends="init">
<!-- Creating view -->
<exec dir="." executable="cmd" os="Windows 2000" output="output2.txt">
<arg line="/c start c:\scripts\c.pl"/>
</exec>
</target>
How should i give command line argument to c.pl?(input to perl program)
 
Glenio Alexandre Nogueira
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to use something like that

<target name="build-xml-indices">
<property name="perl" location="c:\perl\bin\perl.exe"/>
<property name="file" location="findEntities.pl "/>
<property name="arg1" value="blablabla"/>

<exec executable="${perl}" spawn="false">
<arg value="${file}"/>
<arg value="${arg1}"/>
</exec>
</target>

arg1 will be your first argument. I hope it works

Originally posted by kri shan:
Hi Sheila,
<target name="create_view" depends="init">
<!-- Creating view -->
<exec dir="." executable="cmd" os="Windows 2000" output="output2.txt">
<arg line="/c start c:\scripts\c.pl"/>
</exec>
</target>
How should i give command line argument to c.pl?(input to perl program)


[ July 05, 2007: Message edited by: Gl´┐Żnio Alexandre Nogueira ]
[ July 05, 2007: Message edited by: Glenio Alexandre Nogueira ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic