0

I am trying to run a batch file by windows service. The job of the service is to monitor a folder for new files, If it finds then run that batch whose job is to create a log and copy some files.

How ever I can not see that log or any console for that batch (pause is given inside batch file). However no error is also showing apparently. A lot of cmd is open in task manager by the way. Any help. code attached. The batch is ok to run manually.


    public partial class CTT : ServiceBase
    {
        FileSystemWatcher fileWatcher;
        public CTT()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            fileWatcher = new FileSystemWatcher(@"E:\Tags\New folder")
            {
                EnableRaisingEvents = true,
            };
            fileWatcher.Created += FileWatcher_Created;
        }

        private void FileWatcher_Created(object sender, FileSystemEventArgs e)
        {
            Process.Start(@"E:\Tags\TempBatFile.bat");
        }
    }

  • Do you mean "cannot" rather than "can"? Have you tried to debug by adding logging to see if the event handler is called? Have you checked that Process.Start doesn't throw an exception? – Mo B. Sep 03 '20 at 09:26
  • Yes, it should be 'cannot'..And Yes checked those that event handler is called and the Process.Start() does not show any exception. Another things I noticed that the operation like call other exe is doing its function written inside the batch, however creating log folder or renaming things are not working – Needy.Coder Sep 03 '20 at 10:01
  • Does this answer your question? [Executing Batch File in C#](https://stackoverflow.com/questions/5519328/executing-batch-file-in-c-sharp) – kapsiR Sep 03 '20 at 10:02
  • _"A lot of cmd is open in task manager by the way"_ Under which windows user account are they running? Is the service maybe running using the System account, so you cannot see the processes started by it? – bassfader Sep 03 '20 at 10:02

0 Answers0