[Windows] Help creating .NET app for user script SOLVED

Come up with a useful post-processing script? Share it here!
Post Reply
tyrekno
Newbie
Newbie
Posts: 2
Joined: February 27th, 2014, 1:02 pm

[Windows] Help creating .NET app for user script SOLVED

Post by tyrekno »

I'm trying to write my own custom app that will eventually do some renaming and moving. To start, I tried to create a simple app that would get run by sabnzbd and output all of the arguments that get passed into a log file. The code is below. My problem is that I get an exit code of 255, and no code gets run. I can't even catch an exception. My best guess is that sabnzbd has a permission issue with running my app? Is there some property in the project that needs to be configured to allow sabnzbd to run it?

Code: Select all

        private static string logFileName = "log.txt";

        static int Main(string[] args)
        {
            try
            {
                if (args.Count() == 0)
                {
                    Log("NO Arguments");
                }
                else
                {
                    for (int i = 0; i < args.Length; i++) // Loop through array
                    {
                        string argument = args[i];
                        Log(i + " " + argument);
                    }
                }
            }
            catch (Exception e)
            {
                Log(e.Message);
            }
            return 0;
        }

        private static void Log(string logText)
        {
            StreamWriter log;

            if (!File.Exists(logFileName))
            {
                log = new StreamWriter(logFileName);
            }
            else
            {
                log = File.AppendText(logFileName);
            }

            log.WriteLine(DateTime.Now + " - " + logText);
            log.Close();
        }

EDIT: I solved this. I didn't realize it was trying to write the log inside the sabnzbd directory instead of where the script file is located. I declared a full path for the log file and it worked.
Post Reply