0

i edited my code to the following:

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

namespace Search
{
    class Program
    {
        static void Main(string[] args)
        {
            string abc = string.Format("{0}", args[0]);
            string latestversion = string.Format("{1}", args[1]);
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "sslist.exe";
            p.StartInfo.Arguments = "-R -H -h sinsscm01.ds.net" + type;
            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(latestversion, "");
                    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();
        }
    }
}

where string type and string latest version are the arguments parsed.

So, my commandline looks like this:

c:/searchversion.exe "/SASE Lab Tools" "6.70_Extensions/6.70.102/ANT_RELEASE_"

where "/SASE Lab Tools" should be stored as a string abc and "6.70_Extensions/6.70.102/ANT_RELEASE_" should be stored as a string as latestversion.

However i get an error: System.Format.Exception: Index(zero based) must be greater than or equal to zero and less than the size of the argument list at line 14:

string latestversion = string.Format("{1}", args[1]);

Anybody knows whats wrong?

3 Answers 3

2
string latestversion = string.Format("{0}", args[0]);

updated

if you go debugging do you have your args[] filled with data?

Sign up to request clarification or add additional context in comments.

Comments

1

for

string latestversion = string.Format("{1}", args[1]); 

You specified the 2nd item in the array of the string format, for which there isnt one. So the array is out of bounds. you meant

string latestversion = string.Format("{0}", args[1]); 

1 Comment

:) no worries, its an easy one to do, when doing the cut/paste change 0's to 1.. oh not that one :)
0

See abc and latestversion are two different strings. And since you are formatting those one-by-one, you need to start your format specifiers by 0 each time. So, your code should be:

string latestversion = string.Format("{0}", args[1]); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.