ant not executing .exe file

2019-09-17 07:08发布

问题:

my searchversion.exe file is not running in the script..why is that so?

<project name="nightly_build" default="main" basedir="checkout">
    <target name="init">
        <property file="initial.properties"/>
        <property file="C:/Work/lastestbuild.properties"/>
        <tstamp>
            <format property="suffix" pattern="yyyyMMddHHmmss"/>
        </tstamp>
    </target>
    <target name="main" depends="init">
        <sequential>
            <exec executable="C:/Work/Searchversion.exe"/>
                ...
        </sequential>
    </target>
</project>

Searchversion.exe will generate latestbuild.properties file. I do not have any arguments for Searchversion.exe.

Here is the code for searchversion.exe:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Search
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "sslist.exe";
            p.StartInfo.Arguments = "-R -H -h sinsscm01.ds.net /mobile";
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.Start();
            string procOutput = p.StandardOutput.ReadToEnd();
            string procError = p.StandardError.ReadToEnd();
            TextWriter outputlog = new StreamWriter("C:\\Work\\listofsnapshot.txt");
            outputlog.Write(procOutput);
            outputlog.Close();
            string greatestVersionNumber = "";
            using (StreamReader sr = new StreamReader("C:\\Work\\listofsnapshot.txt")) 
            {
                while (sr.Peek() >= 0) 
                {
                    var line = sr.ReadLine();
                    var versionNumber = line.Replace(@"6.70_Extensions/6.70.102/ANT_SASE_RELEASE_", "");
                    if(versionNumber.Length != line.Length)
                    greatestVersionNumber = versionNumber;
                }
            }
            Console.WriteLine(greatestVersionNumber);

            TextWriter latest = new StreamWriter("C:\\Work\\latestbuild.properties");
            latest.Write("Version_Number=" + greatestVersionNumber);
            latest.Close();
        }
    }
}

sslist.exe gets a list of snapshots found in my version control software, and i will get the greatest version number and save it as a text (latestbuild.properties)

回答1:

Two things in your script look odd.

  1. I don't think you need the <sequential> task in the <main> target.
  2. The depends attribute of you <main> target will cause the <init> target to run before Searchversion.exe. So, perhaps it is getting run, just too late.

Assuming #2 is the cause of your problem you should restructure your script to look like this:

<project name="nightly_build" default="main" basedir="checkout">
    <target name="init">
        <exec executable="C:/Work/Searchversion.exe"/>
        <property file="initial.properties"/>
        <property file="C:/Work/lastestbuild.properties"/>
        <tstamp>
            <format property="suffix" pattern="yyyyMMddHHmmss"/>
        </tstamp>
    </target>
    <target name="main" depends="init">
        ...
    </target>
</project>


标签: ant