views:

190

answers:

2

I'm trying to execute iisvdir from an ant script to clean and create a virtual directory before I compile my .net app in Visual Studio. I am running into a couple of strange errors one one build server, but another is running the script without any problem.

    <exec dir="${SYSTEM32}" executable="cscript" failonerror="true">
        <arg line='iisvdir.vbs /create "Default Web Site" ${RS_VIRTUAL_DIR} "${env.WORKSPACE}"'/>
    </exec>

Results in:

     [exec] Microsoft (R) Windows Script Host Version 5.6
  [exec] Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
  [exec]
  [exec] Input Error: Can not find script file "c:\windows\system32\iisvdir.vbs".

And then

    <exec dir="${SYSTEM32}" executable="cmd" failonerror="true">
        <arg line='cscript iisvdir.vbs /create "Default Web Site" ${RS_VIRTUAL_DIR} "${env.WORKSPACE}"'/>
    </exec>

Results in

 [exec] 'reate' is not recognized as an internal or external command,
 [exec] operable program or batch file.

Can someone help me figure out what might be wrong?

A: 

Hi, I don't know if it's the cause of your problems but I notice that you are using a single quote (') for <arg line='. All the examples I've seen use a double quote (") I know you are enclosing items with spaces in double quotes so it may be necessary to escape them out? Perhaps moving the code into a batch file which you can test before running via Ant?

Not sure if this will help but could point you in the right direction.

Andy Robinson
When I first started working on my ant scripts I had a lot of commands that needed to have double quotes inside the command. I found that for the Ant script itself, single or double quotes both behave the same way. This allows me to use single quotes as part of the XML in the script when I need to use double quotes in the actual command.
galuvian
Running the iisvdir command on the command line works just fine. The problem is in getting Ant to run it correctly. The frustrating thing is that I have this working on another build machine, and I'm trying to set up my scripts on a second one and am now encountering this problem. Grr!
galuvian
A: 
  1. Is iisvdir.vbs where you say it is?
  2. To get CMD.EXE to run a command, you need to use the /C switch.

For example:

cmd.exe echo Hello

...ignores the parameters and runs another interactive command prompt as a subshell.

cmd.exe /c echo Hello

...runs the "echo Hello" statement and returns immediately. Note: You can use /K if you want cmd.exe to continue running interactively after running the statement (not usually a good idea in a build script).

Your command:

cmd.exe cscript iisvdir.vbs /create etc.

...is getting parsed as if you'd really said:

cmd.exe /c reat etc.

This is because cmd.exe has (as with most MS command line tools) freaky command line parsing.

Update: Is this a 64-bit OS? If Ant is a 32-bit task, then it'll actually (silently) be looking in C:\Windows\SysWOW64 for cscript.exe and iisvdir.vbs. Are they there? If not, you should use C:\Windows\SysNative. In a 32-bit task, this is aliased to the real C:\Windows\System32 directory.

Roger Lipscombe
Yes, iisvdir is definitely in the system32 folder. The problem with the /c being confused as an argument is exactly what is happening. And I can't find a workaround to execute what I need to. Any thoughts?
galuvian
This is a 64-bit OS, but my default jvm is 32-bits. I should also add that I am able to call "cmd cscript iisvdir.vbs" successfully to /delete a dataset, but it chokes on /create due to /c meaning something to cmd.
galuvian
Yeah, so run `cmd /c cscript iisvdir.vbs /create etc...`
Roger Lipscombe