The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

C# and command lines with Windows Task Scheduler

A bit vague this but any suggestions please.

My program has some command line arguments which work fine. A customer has placed the command line in a batch file and wants to run the program from the Windows Task Scheduler each morning.

Here is the problem, when double clicking the batch file all works well. When leaving task scheduler to run the program the program fails with the error below. Now why would it run from the batch file but not when the batch file is run by the task scheduler? Any ideas much appreciated.

Error: Index was out of range. Must be non-negative and less than the size of the collection.
Steve
Thursday, July 19, 2007
 
 
It looks like task scheduler is not launching the program with the correct number of arguments...
that's my guess
Thursday, July 19, 2007
 
 
Can you show us the offending line(s) of code?
DLarsen Send private email
Thursday, July 19, 2007
 
 
Is the command line in the batch file escaped properly?  That might cause your startup arguments to parse badly.
a former big-fiver Send private email
Thursday, July 19, 2007
 
 
Permissions issue manifesting itself oddly?
Cade Roux Send private email
Thursday, July 19, 2007
 
 
You should check the number of command-line arguments before accessing them and display an error message ("Missing argument" or similar) if the number of arguments isn't what you're expecting.  Then your customer will get an appropriate error message instead of "index out of range" and with a bit of luck will try to work out for himself what he's doing wrong instead of calling you for support.
Joe
Friday, July 20, 2007
 
 
There are a variety of differences between running something from Scheduled Tasks and from the desktop:
1. Current directory
2. Scheduled Tasks can be run as a different user
3. Environment variables are completely different - in particular, PATH probably isn't set "correctly"

Most likely one or the other of these is your problem. Sounds like some more-helpful error messages would be a good place to start.

Have you tried running your application from Scheduled Tasks on your own computer, and does it reproduce the customer's failure?
Mark Bessey Send private email
Monday, July 23, 2007
 
 
Also, the maximum command length in Windows scheduler is quite small (I'd say 128 bytes).
Robert Premuz Send private email
Thursday, August 02, 2007
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz