You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Chris <ch...@ooc2000.com> on 2001/10/04 19:01:06 UTC

Can't get to work

Hi all,

I was just messing around with <exec>, with an eye towards using Ant to 
take over building some C projects. Here's my simple build file:

<project name="DirAnt" default="init">
         <target name="init">
                 <exec executable="dir"/>
         </target>
</project>

The error I get when I try and run it is below. I've using Windows 2000, 
and Sun's JDK 1.3.1.

Any ideas?
Thanks,
Chris

------------ Error message -------------------

P:\dev\lab\ant>ant -buildfile dir.xml
Buildfile: dir.xml

init:

BUILD FAILED

P:\dev\lab\ant\dir.xml:4: Execute failed: java.io.IOException: 
CreateProcess: dir error=2
--- Nested Exception ---
java.io.IOException: CreateProcess: dir 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:551)
         at java.lang.reflect.Method.invoke(Native Method)
         at 
org.apache.tools.ant.taskdefs.Execute$Java13CommandLauncher.exec(Execute.java:509)
         at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:329)
         at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:228)
         at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:162)
         at org.apache.tools.ant.Target.execute(Target.java:153)
         at org.apache.tools.ant.Project.runTarget(Project.java:898)
         at org.apache.tools.ant.Project.executeTarget(Project.java:536)
         at org.apache.tools.ant.Project.executeTargets(Project.java:510)
         at org.apache.tools.ant.Main.runBuild(Main.java:421)
         at org.apache.tools.ant.Main.main(Main.java:149)

Total time: 0 seconds


Re: Can't get to work

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
Conor,

Sorry about that 'cls' mistake, and you are absolutely right of course.

I've updated the FAQ entry: http://www.jguru.com/faq/view.jsp?EID=511266 and
made sure to specify "shell command" rather than just "command".

    Erik



----- Original Message -----
From: "Conor MacNeill" <co...@cortexebusiness.com.au>
To: <an...@jakarta.apache.org>
Sent: Friday, October 05, 2001 7:59 AM
Subject: Re: Can't get <exec> to work


> Erik Hatcher wrote:
>
> > I just promoted this to a FAQ at jGuru (it takes an hour or so for it to
> > appear as an FAQ), but here's a link to the forum entry:
> >
> >     http://www.jguru.com/forums/view.jsp?EID=503205
> >
> > (answer a few entries down)
> >
> >     Erik
>
> Is that this one?
>
>  > To <exec> a command on Windows, you must execute the command shell
> followed by the command you want. For example:
>  >
>  > <exec executable="cmd">
>  > <arg line="/c cls"/>
>  > </exec>
>  >
>  > The '/c' is there to exit the spawned command shell after executing
> the specified command.
>
> It is not quite true. You can execute most commands without executing a
> command shell. The cases where that is not true is where you are trying
> to execute a command.com builtin. Also the example above probably won't
> work - I don't have NT running anymore, but I am pretty sure the above
> won't clear the screen, presumably because it is actually clearing a
> different shell.
>
> Conor
>
>
>


Re: Can't get to work

Posted by Conor MacNeill <co...@cortexebusiness.com.au>.
Erik Hatcher wrote:

> I just promoted this to a FAQ at jGuru (it takes an hour or so for it to
> appear as an FAQ), but here's a link to the forum entry:
> 
>     http://www.jguru.com/forums/view.jsp?EID=503205
> 
> (answer a few entries down)
> 
>     Erik

Is that this one?

 > To <exec> a command on Windows, you must execute the command shell 
followed by the command you want. For example:
 >
 > <exec executable="cmd">
 > <arg line="/c cls"/>
 > </exec>
 >
 > The '/c' is there to exit the spawned command shell after executing 
the specified command.

It is not quite true. You can execute most commands without executing a 
command shell. The cases where that is not true is where you are trying 
to execute a command.com builtin. Also the example above probably won't 
work - I don't have NT running anymore, but I am pretty sure the above 
won't clear the screen, presumably because it is actually clearing a 
different shell.

Conor



Re: Can't get to work

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
Chris,

Yes, your explanation is correct.

    Erik

----- Original Message -----
From: "Chris" <ch...@ooc2000.com>
To: <an...@jakarta.apache.org>
Sent: Thursday, October 04, 2001 1:23 PM
Subject: Re: Can't get <exec> to work


> I can dig it . . . the program I want isn't dir, the program is the shell
> (cmd), with a command line arg of dir. That makes sense.
>
> My guess is that while under Unix ls is an actual program, under DOS dir
> isn't a program - it's a shell command. So under Unix you wouldn't launch
> the shell. Right?
>
> Thanks Erik, & say hello to my friend Alex Chaffee at jGuru for me.
>
> - Chris
>
> At 10:22 AM 10/4/2001 -0700, you wrote:
> >I just promoted this to a FAQ at jGuru (it takes an hour or so for it to
> >appear as an FAQ), but here's a link to the forum entry:
> >
> >     http://www.jguru.com/forums/view.jsp?EID=503205
> >
> >(answer a few entries down)
>
>


Re: Can't get to work

Posted by Chris <ch...@ooc2000.com>.
I can dig it . . . the program I want isn't dir, the program is the shell 
(cmd), with a command line arg of dir. That makes sense.

My guess is that while under Unix ls is an actual program, under DOS dir 
isn't a program - it's a shell command. So under Unix you wouldn't launch 
the shell. Right?

Thanks Erik, & say hello to my friend Alex Chaffee at jGuru for me.

- Chris

At 10:22 AM 10/4/2001 -0700, you wrote:
>I just promoted this to a FAQ at jGuru (it takes an hour or so for it to
>appear as an FAQ), but here's a link to the forum entry:
>
>     http://www.jguru.com/forums/view.jsp?EID=503205
>
>(answer a few entries down)


Re: Can't get to work

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
I just promoted this to a FAQ at jGuru (it takes an hour or so for it to
appear as an FAQ), but here's a link to the forum entry:

    http://www.jguru.com/forums/view.jsp?EID=503205

(answer a few entries down)

    Erik

----- Original Message -----
From: "Chris" <ch...@ooc2000.com>
To: <an...@jakarta.apache.org>
Sent: Thursday, October 04, 2001 10:01 AM
Subject: Can't get <exec> to work


> Hi all,
>
> I was just messing around with <exec>, with an eye towards using Ant to
> take over building some C projects. Here's my simple build file:
>
> <project name="DirAnt" default="init">
>          <target name="init">
>                  <exec executable="dir"/>
>          </target>
> </project>
>
> The error I get when I try and run it is below. I've using Windows 2000,
> and Sun's JDK 1.3.1.
>
> Any ideas?
> Thanks,
> Chris
>
> ------------ Error message -------------------
>
> P:\dev\lab\ant>ant -buildfile dir.xml
> Buildfile: dir.xml
>
> init:
>
> BUILD FAILED
>
> P:\dev\lab\ant\dir.xml:4: Execute failed: java.io.IOException:
> CreateProcess: dir error=2
> --- Nested Exception ---
> java.io.IOException: CreateProcess: dir 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:551)
>          at java.lang.reflect.Method.invoke(Native Method)
>          at
>
org.apache.tools.ant.taskdefs.Execute$Java13CommandLauncher.exec(Execute.jav
a:509)
>          at
org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:329)
>          at
org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:228)
>          at
org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:162)
>          at org.apache.tools.ant.Target.execute(Target.java:153)
>          at org.apache.tools.ant.Project.runTarget(Project.java:898)
>          at org.apache.tools.ant.Project.executeTarget(Project.java:536)
>          at org.apache.tools.ant.Project.executeTargets(Project.java:510)
>          at org.apache.tools.ant.Main.runBuild(Main.java:421)
>          at org.apache.tools.ant.Main.main(Main.java:149)
>
> Total time: 0 seconds
>
>


Re: Can't get to work

Posted by Diane Holt <ho...@yahoo.com>.
If you're running 1.3, it could be the antRun line-endings problem. See:

  http://jakarta.apache.org/ant/faq.html#remove-cr

Or it could be that 'dir' is a Windows built-in -- I think there was a
discussion awhile back about that being a problem (check the ant-user
archive). Consider trying it with a different command.

Diane

--- Chris <ch...@ooc2000.com> wrote:
> Hi all,
> 
> I was just messing around with <exec>, with an eye towards using Ant to 
> take over building some C projects. Here's my simple build file:
> 
> <project name="DirAnt" default="init">
>          <target name="init">
>                  <exec executable="dir"/>
>          </target>
> </project>
> 
> The error I get when I try and run it is below. I've using Windows 2000,
> 
> and Sun's JDK 1.3.1.
> 
> Any ideas?
> Thanks,
> Chris
> 
> ------------ Error message -------------------
> 
> P:\dev\lab\ant>ant -buildfile dir.xml
> Buildfile: dir.xml
> 
> init:
> 
> BUILD FAILED
> 
> P:\dev\lab\ant\dir.xml:4: Execute failed: java.io.IOException: 
> CreateProcess: dir error=2
> --- Nested Exception ---
> java.io.IOException: CreateProcess: dir 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:551)
>          at java.lang.reflect.Method.invoke(Native Method)
>          at 
>
org.apache.tools.ant.taskdefs.Execute$Java13CommandLauncher.exec(Execute.java:509)
>          at
> org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:329)
>          at
> org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:228)
>          at
> org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:162)
>          at org.apache.tools.ant.Target.execute(Target.java:153)
>          at org.apache.tools.ant.Project.runTarget(Project.java:898)
>          at org.apache.tools.ant.Project.executeTarget(Project.java:536)
>          at
> org.apache.tools.ant.Project.executeTargets(Project.java:510)
>          at org.apache.tools.ant.Main.runBuild(Main.java:421)
>          at org.apache.tools.ant.Main.main(Main.java:149)
> 
> Total time: 0 seconds
> 


=====
(holtdl@yahoo.com)



__________________________________________________
Do You Yahoo!?
NEW from Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
http://geocities.yahoo.com/ps/info1