Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console Application Args to Task Scheduler Parameters (CLOSED)

I've done a lot of research on this subject and all I found were misleading sites about information I wasn't looking for. So I hope anyone here can give me a solid explanation.

Basicly, I have a program, which I want to use in Task Scheduler. But whatever parameter I give in the box to put them in, it keeps saying The index is located outside of the array bounds.

I understand that parameters are linked to the args? So can anyone tell me what is wrong with my code?

public static void Main(string[] args)
{
   string paramList = string.Join("", args);
   string[] parameter = paramList.Split(',');

   string ScanPath = parameter[0]; //Which directory to scan
   string MailToAddress = parameter[1]; //Which e-mail to send the log to
   string ScanHours = parameter[2]; //How many hours to scan
}

I found this somewhere on codeproject. I assumed that the first arg is linked to the first parameter, etc, etc.

In Task Scheduler I basicly browse to the released executable: enter image description here

Of course the path and mail part is much longer when running the program, but this is just for example.

Do I need to remove the commas? And/or add - in front of every parameter? Or is it something completely else?

Thanks in advance!

like image 887
vascomakker Avatar asked Oct 28 '25 12:10

vascomakker


2 Answers

Usually command line arguments are split by a single space character, not comma's. Furthermore, if any of your arguments contain spaces, you need to wrap the argument in double quotes:

"C:\My Documents\xxx" [email protected] 10

I don't know how the task scheduler supplies its parameters, but you could of course log the arguments before using them, to see exactly what's passed to your application.

like image 65
C.Evenhuis Avatar answered Oct 31 '25 03:10

C.Evenhuis


Though i think you know this allready, just to be sure: You need to seperate parameters by blanks. Also if parameters contains blanks (path for example) put them in doublequotes.

Why dont you write a simple test-app that dumps the complete paramsarray into a textfile. Then you should know how to interprete correctly.

like image 40
CSharpie Avatar answered Oct 31 '25 01:10

CSharpie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!